addr_monitor
This crate is for doing one thing and one thing only; safely monitoring an address for updates.
It exposes hardware monitors on x86_64 via x86_intr with fallbacks using spin loops.
Usage
There are two modules to use:
hardware: exposesHardwareMonitorfor directly usingx86_64userspace hardware monitors on Intel and AMDblocking: synchronization primitives built on top of the hardware monitor like CAS loops and conditional waits
To use them in code:
swap_on_write is nothing more than a CAS loop.
let value = new;
let barrier = new;
let mut handles = Vecnew;
for new_value in 1..=WRITERS
let results: = handles
.into_iter
.map
.collect;
let final_value = value.load;
assert!;
assert_eq!;
for in &results
where WRITERS is a constant i32.
cond_wait_eq and cond_wait_ne block the thread until the atomic value is equal to or not equal to the desired value, respectively.
// cond_wait_eq
let value = new;
let watched = clone;
let = channel;
let = channel;
let handle = spawn;
started_rx.recv.unwrap;
assert!;
value.store;
finished_rx
.recv_timeout
.unwrap;
handle.join.unwrap;
// cond_wait_ne
let value = new;
let watched = clone;
let = channel;
let = channel;
let handle = spawn;
started_rx.recv.unwrap;
assert!;
value.store;
finished_rx
.recv_timeout
.unwrap;
handle.join.unwrap;
block_on_write is another conditional wait but waits until the atomic value has changed from its starting value when it's called:
let value = new;
let watched = clone;
let handle = spawn;
sleep;
value.store;
sleep;
assert!;
value.store;
handle.join.unwrap;
or using HardwareMonitor directly:
let support = platform;
loop