@@ -318,20 +318,38 @@ impl Builder {
318
318
// Free functions
319
319
////////////////////////////////////////////////////////////////////////////////
320
320
321
- /// Spawns a new thread, returning a `JoinHandle` for it.
321
+ /// Spawns a new thread, returning a [ `JoinHandle`] for it.
322
322
///
323
323
/// The join handle will implicitly *detach* the child thread upon being
324
324
/// dropped. In this case, the child thread may outlive the parent (unless
325
325
/// the parent thread is the main thread; the whole process is terminated when
326
- /// the main thread finishes.) Additionally, the join handle provides a `join`
326
+ /// the main thread finishes). Additionally, the join handle provides a [ `join`]
327
327
/// method that can be used to join the child thread. If the child thread
328
- /// panics, `join` will return an `Err` containing the argument given to
329
- /// `panic`.
328
+ /// panics, [ `join`] will return an [ `Err`] containing the argument given to
329
+ /// [ `panic`] .
330
330
///
331
331
/// # Panics
332
332
///
333
- /// Panics if the OS fails to create a thread; use `Builder::spawn`
333
+ /// Panics if the OS fails to create a thread; use [ `Builder::spawn`]
334
334
/// to recover from such errors.
335
+ ///
336
+ /// [`JoinHandle`]: ../../std/thread/struct.JoinHandle.html
337
+ /// [`join`]: ../../std/thread/struct.JoinHandle.html#method.join
338
+ /// [`Err`]: ../../std/result/enum.Result.html#variant.Err
339
+ /// [`panic!`]: ../../std/macro.panic.html
340
+ /// [`Builder::spawn`]: ../../std/thread/struct.Builder.html#method.spawn
341
+ ///
342
+ /// # Examples
343
+ ///
344
+ /// ```
345
+ /// use std::thread;
346
+ ///
347
+ /// let handler = thread::spawn(|| {
348
+ /// // thread code
349
+ /// });
350
+ ///
351
+ /// handler.join().unwrap();
352
+ /// ```
335
353
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
336
354
pub fn spawn < F , T > ( f : F ) -> JoinHandle < T > where
337
355
F : FnOnce ( ) -> T , F : Send + ' static , T : Send + ' static
@@ -341,7 +359,7 @@ pub fn spawn<F, T>(f: F) -> JoinHandle<T> where
341
359
342
360
/// Gets a handle to the thread that invokes it.
343
361
///
344
- /// #Examples
362
+ /// # Examples
345
363
///
346
364
/// Getting a handle to the current thread with `thread::current()`:
347
365
///
@@ -366,6 +384,14 @@ pub fn current() -> Thread {
366
384
}
367
385
368
386
/// Cooperatively gives up a timeslice to the OS scheduler.
387
+ ///
388
+ /// # Examples
389
+ ///
390
+ /// ```
391
+ /// use std::thread;
392
+ ///
393
+ /// thread::yield_now();
394
+ /// ```
369
395
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
370
396
pub fn yield_now ( ) {
371
397
imp:: Thread :: yield_now ( )
@@ -375,7 +401,7 @@ pub fn yield_now() {
375
401
///
376
402
/// # Examples
377
403
///
378
- /// ```rust, should_panic
404
+ /// ```should_panic
379
405
/// use std::thread;
380
406
///
381
407
/// struct SomeStruct;
@@ -413,6 +439,15 @@ pub fn panicking() -> bool {
413
439
/// specifics or platform-dependent functionality. Note that on unix platforms
414
440
/// this function will not return early due to a signal being received or a
415
441
/// spurious wakeup.
442
+ ///
443
+ /// # Examples
444
+ ///
445
+ /// ```no_run
446
+ /// use std::thread;
447
+ ///
448
+ /// // Let's sleep for 2 seconds:
449
+ /// thread::sleep_ms(2000);
450
+ /// ```
416
451
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
417
452
#[ rustc_deprecated( since = "1.6.0" , reason = "replaced by `std::thread::sleep`" ) ]
418
453
pub fn sleep_ms ( ms : u32 ) {
@@ -433,7 +468,7 @@ pub fn sleep_ms(ms: u32) {
433
468
///
434
469
/// # Examples
435
470
///
436
- /// ```rust, no_run
471
+ /// ```no_run
437
472
/// use std::{thread, time};
438
473
///
439
474
/// let ten_millis = time::Duration::from_millis(10);
0 commit comments