|
85 | 85 | //! value produced by the child thread, or `Err` of the value given to
|
86 | 86 | //! a call to `panic!` if the child panicked.
|
87 | 87 | //!
|
88 |
| -//! ## Scoped threads |
89 |
| -//! |
90 |
| -//! The `spawn` method does not allow the child and parent threads to |
91 |
| -//! share any stack data, since that is not safe in general. However, |
92 |
| -//! `scoped` makes it possible to share the parent's stack by forcing |
93 |
| -//! a join before any relevant stack frames are popped: |
94 |
| -//! |
95 |
| -//! ```rust |
96 |
| -//! # #![feature(scoped)] |
97 |
| -//! use std::thread; |
98 |
| -//! |
99 |
| -//! let guard = thread::scoped(move || { |
100 |
| -//! // some work here |
101 |
| -//! }); |
102 |
| -//! |
103 |
| -//! // do some other work in the meantime |
104 |
| -//! let output = guard.join(); |
105 |
| -//! ``` |
106 |
| -//! |
107 |
| -//! The `scoped` function doesn't return a `Thread` directly; instead, |
108 |
| -//! it returns a *join guard*. The join guard is an RAII-style guard |
109 |
| -//! that will automatically join the child thread (block until it |
110 |
| -//! terminates) when it is dropped. You can join the child thread in |
111 |
| -//! advance by calling the `join` method on the guard, which will also |
112 |
| -//! return the result produced by the thread. A handle to the thread |
113 |
| -//! itself is available via the `thread` method of the join guard. |
114 |
| -//! |
115 | 88 | //! ## Configuring threads
|
116 | 89 | //!
|
117 | 90 | //! A new thread can be configured before it is spawned via the `Builder` type,
|
@@ -288,7 +261,7 @@ impl Builder {
|
288 | 261 | /// upon being dropped. Because the child thread may refer to data on the
|
289 | 262 | /// current thread's stack (hence the "scoped" name), it cannot be detached;
|
290 | 263 | /// it *must* be joined before the relevant stack frame is popped. See the
|
291 |
| - /// module documentation for additional details. |
| 264 | + /// documentation on `thread::scoped` for additional details. |
292 | 265 | ///
|
293 | 266 | /// # Errors
|
294 | 267 | ///
|
@@ -388,12 +361,30 @@ pub fn spawn<F, T>(f: F) -> JoinHandle<T> where
|
388 | 361 |
|
389 | 362 | /// Spawns a new *scoped* thread, returning a `JoinGuard` for it.
|
390 | 363 | ///
|
391 |
| -/// The join guard can be used to explicitly join the child thread (via |
392 |
| -/// `join`), returning `Result<T>`, or it will implicitly join the child |
393 |
| -/// upon being dropped. Because the child thread may refer to data on the |
394 |
| -/// current thread's stack (hence the "scoped" name), it cannot be detached; |
395 |
| -/// it *must* be joined before the relevant stack frame is popped. See the |
396 |
| -/// module documentation for additional details. |
| 364 | +/// The `spawn` method does not allow the child and parent threads to |
| 365 | +/// share any stack data, since that is not safe in general. However, |
| 366 | +/// `scoped` makes it possible to share the parent's stack by forcing |
| 367 | +/// a join before any relevant stack frames are popped: |
| 368 | +/// |
| 369 | +/// ```rust |
| 370 | +/// # #![feature(scoped)] |
| 371 | +/// use std::thread; |
| 372 | +/// |
| 373 | +/// let guard = thread::scoped(move || { |
| 374 | +/// // some work here |
| 375 | +/// }); |
| 376 | +/// |
| 377 | +/// // do some other work in the meantime |
| 378 | +/// let output = guard.join(); |
| 379 | +/// ``` |
| 380 | +/// |
| 381 | +/// The `scoped` function doesn't return a `Thread` directly; instead, it |
| 382 | +/// returns a *join guard*. The join guard can be used to explicitly join |
| 383 | +/// the child thread (via `join`), returning `Result<T>`, or it will |
| 384 | +/// implicitly join the child upon being dropped. Because the child thread |
| 385 | +/// may refer to data on the current thread's stack (hence the "scoped" |
| 386 | +/// name), it cannot be detached; it *must* be joined before the relevant |
| 387 | +/// stack frame is popped. |
397 | 388 | ///
|
398 | 389 | /// # Panics
|
399 | 390 | ///
|
|
0 commit comments