diff options
| author | Aaron Turon <aturon@mozilla.com> | 2014-12-14 00:05:32 -0800 |
|---|---|---|
| committer | Aaron Turon <aturon@mozilla.com> | 2014-12-18 23:31:52 -0800 |
| commit | a27fbac86849e07a0a6c746869d8f78319bd3a16 (patch) | |
| tree | f17d75fcdd4d353f5ff919e491a5fc71252c0ef1 /src/libstd/thread_local | |
| parent | 13f302d0c5dd3a88426da53ba07cdbe16459635b (diff) | |
| download | rust-a27fbac86849e07a0a6c746869d8f78319bd3a16.tar.gz rust-a27fbac86849e07a0a6c746869d8f78319bd3a16.zip | |
Revise std::thread API to join by default
This commit is part of a series that introduces a `std::thread` API to replace `std::task`. In the new API, `spawn` returns a `JoinGuard`, which by default will join the spawned thread when dropped. It can also be used to join explicitly at any time, returning the thread's result. Alternatively, the spawned thread can be explicitly detached (so no join takes place). As part of this change, Rust processes now terminate when the main thread exits, even if other detached threads are still running, moving Rust closer to standard threading models. This new behavior may break code that was relying on the previously implicit join-all. In addition to the above, the new thread API also offers some built-in support for building blocking abstractions in user space; see the module doc for details. Closes #18000 [breaking-change]
Diffstat (limited to 'src/libstd/thread_local')
| -rw-r--r-- | src/libstd/thread_local/mod.rs | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/libstd/thread_local/mod.rs b/src/libstd/thread_local/mod.rs index 4c052a4ce09..4c33d1c418d 100644 --- a/src/libstd/thread_local/mod.rs +++ b/src/libstd/thread_local/mod.rs @@ -68,6 +68,7 @@ pub mod scoped; /// /// ``` /// use std::cell::RefCell; +/// use std::thread::Thread; /// /// thread_local!(static FOO: RefCell<uint> = RefCell::new(1)); /// @@ -77,12 +78,12 @@ pub mod scoped; /// }); /// /// // each thread starts out with the initial value of 1 -/// spawn(move|| { +/// Thread::spawn(move|| { /// FOO.with(|f| { /// assert_eq!(*f.borrow(), 1); /// *f.borrow_mut() = 3; /// }); -/// }); +/// }).detach(); /// /// // we retain our original value of 2 despite the child thread /// FOO.with(|f| { @@ -533,7 +534,7 @@ mod tests { } } - Thread::with_join(move|| { + Thread::spawn(move|| { drop(S1); }).join(); } @@ -551,7 +552,7 @@ mod tests { } } - Thread::with_join(move|| unsafe { + Thread::spawn(move|| unsafe { K1.with(|s| *s.get() = Some(S1)); }).join(); } |
