This crate allows you to store a value that you can later take out atomically. As this crate uses atomics, no locking is involved in taking the value out.
As an example, you could store the
Sender of an oneshot channel in an
AtomicTake, which would allow you to notify the first time a closure is called.
use AtomicTake; use oneshot; let = channel; let take = new; let closure = move || ; closure; assert_eq!; closure; // This does nothing.
Additionally the closure above can be called concurrently from many threads. For
example, if you put the
AtomicTake in an
Arc, you can share it between several
threads and receive a message from the first thread to run.
use thread; use Arc; use AtomicTake; use oneshot; let = channel; // Use an Arc to share the AtomicTake between several threads. let take = new; // Spawn three threads and try to send a message from each. let mut handles = Vecnew; for i in 0..3 // Wait for all three threads to finish. for handle in handles // After all the threads finished, try to send again. if let Some = take.take // Confirm that one of the first three threads got to send the message first. assert!;
This crate does not require the standard library.