simple/
simple.rs

1use std::sync::atomic::Ordering;
2use stoplight;
3
4fn main() {
5    // spawn our task, this creates a new OS thread.
6    let th = stoplight::spawn(|stop| {
7        while !stop.load(Ordering::Relaxed) {}
8        42
9    });
10
11    // stop() signals the thread to stop, and then join returns its return value.
12    th.stop();
13    assert_eq!(th.join().unwrap(), 42);
14}