@@ -180,8 +180,33 @@ pub use self::local::{LocalKey, LocalKeyState};
180
180
// Builder
181
181
////////////////////////////////////////////////////////////////////////////////
182
182
183
- /// Thread configuration. Provides detailed control over the properties
184
- /// and behavior of new threads.
183
+ /// Thread factory, which can be used in order to configure the properties of
184
+ /// a new thread.
185
+ ///
186
+ /// Methods can be chained on it in order to configure it.
187
+ ///
188
+ /// The two configurations available are:
189
+ ///
190
+ /// - [`name`]: allows to give a name to the thread which is currently
191
+ /// only used in `panic` messages.
192
+ /// - [`stack_size`]: specifies the desired stack size. Note that this can
193
+ /// be overriden by the OS.
194
+ ///
195
+ /// If the [`stack_size`] field is not specified, the stack size
196
+ /// will be the `RUST_MIN_STACK` environment variable. If it is
197
+ /// not specified either, a sensible default will be set.
198
+ ///
199
+ /// If the [`name`] field is not specified, the thread will not be named.
200
+ ///
201
+ /// The [`spawn`] method will take ownership of the builder and create an
202
+ /// [`io::Result`] to the thread handle with the given configuration.
203
+ ///
204
+ /// The [`thread::spawn`] free function uses a `Builder` with default
205
+ /// configuration and [`unwrap`]s its return value.
206
+ ///
207
+ /// You may want to use [`spawn`] instead of [`thread::spawn`], when you want
208
+ /// to recover from a failure to launch a thread, indeed the free function will
209
+ /// panick where the `Builder` method will return a [`io::Result`].
185
210
///
186
211
/// # Examples
187
212
///
@@ -196,6 +221,13 @@ pub use self::local::{LocalKey, LocalKeyState};
196
221
///
197
222
/// handler.join().unwrap();
198
223
/// ```
224
+ ///
225
+ /// [`thread::spawn`]: ../../std/thread/fn.spawn.html
226
+ /// [`stack_size`]: ../../std/thread/struct.Builder.html#method.stack_size
227
+ /// [`name`]: ../../std/thread/struct.Builder.html#method.name
228
+ /// [`spawn`]: ../../std/thread/struct.Builder.html#method.spawn
229
+ /// [`io::Result`]: ../../std/io/type.Result.html
230
+ /// [`unwrap`]: ../../std/result/enum.Result.html#method.unwrap
199
231
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
200
232
#[ derive( Debug ) ]
201
233
pub struct Builder {
@@ -209,11 +241,6 @@ impl Builder {
209
241
/// Generates the base configuration for spawning a thread, from which
210
242
/// configuration methods can be chained.
211
243
///
212
- /// If the [`stack_size`] field is not specified, the stack size
213
- /// will be the `RUST_MIN_STACK` environment variable. If it is
214
- /// not specified either, a sensible default will be set (2MB as
215
- /// of the writting of this doc).
216
- ///
217
244
/// # Examples
218
245
///
219
246
/// ```
@@ -229,8 +256,6 @@ impl Builder {
229
256
///
230
257
/// handler.join().unwrap();
231
258
/// ```
232
- ///
233
- /// [`stack_size`]: ../../std/thread/struct.Builder.html#method.stack_size
234
259
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
235
260
pub fn new ( ) -> Builder {
236
261
Builder {
@@ -280,9 +305,10 @@ impl Builder {
280
305
self
281
306
}
282
307
283
- /// Spawns a new thread, and returns a join handle for it.
308
+ /// Spawns a new thread by taking ownership of the `Builder`, and returns an
309
+ /// [`io::Result`] to its [`JoinHandle`].
284
310
///
285
- /// The child thread may outlive the parent (unless the parent thread
311
+ /// The spawned thread may outlive the caller (unless the caller thread
286
312
/// is the main thread; the whole process is terminated when the main
287
313
/// thread finishes). The join handle can be used to block on
288
314
/// termination of the child thread, including recovering its panics.
@@ -297,6 +323,7 @@ impl Builder {
297
323
///
298
324
/// [`spawn`]: ../../std/thread/fn.spawn.html
299
325
/// [`io::Result`]: ../../std/io/type.Result.html
326
+ /// [`JoinHandle`]: ../../std/thread/struct.JoinHandle.html
300
327
///
301
328
/// # Examples
302
329
///
0 commit comments