| Crates.io | sparking-lot-core |
| lib.rs | sparking-lot-core |
| version | 0.1.3 |
| created_at | 2023-11-20 20:17:53.992192+00 |
| updated_at | 2023-11-30 22:24:54.477635+00 |
| description | A simple implementation of parking on addresses. |
| homepage | |
| repository | https://github.com/JuliusEmperorOfRome/sparking-lot-core |
| max_upload_size | |
| id | 1042799 |
| size | 72,637 |
s(implified-)parking-lot-core is a simplified version of parking_lot_core,
the backend of parking_lot. It doesn't include timeouts and park or unpark
tokens, and doesn't readjust based on thread count, so going above certain thread
counts (96 by default, 384 with the more-concurrency feature), will
lead to worse scaling than parking_lot_core. However, it has static memory usage
and, most importantly, sparking-lot-core has loom 0.7
support with --cfg loom for concurrency testing.
First, add this to your Cargo.toml:
[dependencies]
sparking-lot-core = "0.1"
Then use it:
use sparking_lot_core::{park, unpark_one};
use std::sync::atomic::{AtomicBool, Ordering::Relaxed};
use std::thread;
fn main() {
static WAKE_UP: AtomicBool = AtomicBool::new(false);
let t = thread::spawn(|| {
unsafe{
park(&WAKE_UP as *const _ as *const _, || {
!WAKE_UP.load(Relaxed)
});
};
});
/* Since Relaxed stores/loads are used, this wouldn't guarantee
* the ordering of loads/stores to other variables.
*
* But this is guaranteed to exit.
*/
WAKE_UP.store(true, Relaxed);
unpark_one(&WAKE_UP as *const _ as *const _);
t.join().unwrap();
}
loomloom is enabled with --cfg loom. When running loom tests, it's recommended to enable the loom-test feature, as the default test implementation is severely limited. The old behaviour
is described in the docs.
This project is licensed under the MIT LICENSE