macro_rules! go_ref {
( $( $tokens:tt )+ ) => { ... };
}
Expand description
Spawns a thread to execute the given code. Any captured variables will be borrowed by the spawned thread.
The thread’s handle will be stored in thread-local storage until joined by
join!
or join_all!
.
§Examples
use go_spawn::go_ref;
use std::sync::{
atomic::{AtomicI64, Ordering},
};
go_ref!(expensive_background_work());
static COUNTER: AtomicI64 = AtomicI64::new(0);
go_ref! {
for _ in 0..1_000_000 {
COUNTER.fetch_add(1, Ordering::SeqCst);
}
}