Open
Description
The documentation for std::thread::JoinHandle::join()
guarantees that all memory operations performed by the joined thread are visible in the joining thread before join()
returns:
[...] In other words, all operations performed by that thread happen before all operations that happen after join returns.
The documentation does not give such guarantees for std::thread::spawn()
and the associated [Builder::spawn
].
Obviously, such guarantee already exists implicitly:
fn main() {
let s = "Foo".to_string();
std::thread::spawn(move || {
// All memory-operations performed by the spawning thread
// are visible (happened-before) when the closure starts
// executing, even though they have no explicit ordering.
println!("{s}");
}).join().unwrap();
}
Can we update the documentation on std::thread::spawn()
(and friends) to explicitly make this guarantee?