Add missing urls for thread doc module
This commit is contained in:
@@ -17,13 +17,11 @@
|
|||||||
//! provide some built-in support for low-level synchronization.
|
//! provide some built-in support for low-level synchronization.
|
||||||
//!
|
//!
|
||||||
//! Communication between threads can be done through
|
//! Communication between threads can be done through
|
||||||
//! [channels](../../std/sync/mpsc/index.html), Rust's message-passing
|
//! [channels], Rust's message-passing types, along with [other forms of thread
|
||||||
//! types, along with [other forms of thread
|
|
||||||
//! synchronization](../../std/sync/index.html) and shared-memory data
|
//! synchronization](../../std/sync/index.html) and shared-memory data
|
||||||
//! structures. In particular, types that are guaranteed to be
|
//! structures. In particular, types that are guaranteed to be
|
||||||
//! threadsafe are easily shared between threads using the
|
//! threadsafe are easily shared between threads using the
|
||||||
//! atomically-reference-counted container,
|
//! atomically-reference-counted container, [`Arc`].
|
||||||
//! [`Arc`](../../std/sync/struct.Arc.html).
|
|
||||||
//!
|
//!
|
||||||
//! Fatal logic errors in Rust cause *thread panic*, during which
|
//! Fatal logic errors in Rust cause *thread panic*, during which
|
||||||
//! a thread will unwind the stack, running destructors and freeing
|
//! a thread will unwind the stack, running destructors and freeing
|
||||||
@@ -40,7 +38,7 @@
|
|||||||
//!
|
//!
|
||||||
//! ## Spawning a thread
|
//! ## Spawning a thread
|
||||||
//!
|
//!
|
||||||
//! A new thread can be spawned using the `thread::spawn` function:
|
//! A new thread can be spawned using the [`thread::spawn`][`spawn`] function:
|
||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```rust
|
||||||
//! use std::thread;
|
//! use std::thread;
|
||||||
@@ -55,7 +53,7 @@
|
|||||||
//! it), unless this parent is the main thread.
|
//! it), unless this parent is the main thread.
|
||||||
//!
|
//!
|
||||||
//! The parent thread can also wait on the completion of the child
|
//! The parent thread can also wait on the completion of the child
|
||||||
//! thread; a call to `spawn` produces a `JoinHandle`, which provides
|
//! thread; a call to [`spawn`] produces a [`JoinHandle`], which provides
|
||||||
//! a `join` method for waiting:
|
//! a `join` method for waiting:
|
||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```rust
|
||||||
@@ -68,13 +66,13 @@
|
|||||||
//! let res = child.join();
|
//! let res = child.join();
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//! The `join` method returns a `Result` containing `Ok` of the final
|
//! The [`join`] method returns a [`Result`] containing [`Ok`] of the final
|
||||||
//! value produced by the child thread, or `Err` of the value given to
|
//! value produced by the child thread, or [`Err`] of the value given to
|
||||||
//! a call to `panic!` if the child panicked.
|
//! a call to [`panic!`] if the child panicked.
|
||||||
//!
|
//!
|
||||||
//! ## Configuring threads
|
//! ## Configuring threads
|
||||||
//!
|
//!
|
||||||
//! A new thread can be configured before it is spawned via the `Builder` type,
|
//! A new thread can be configured before it is spawned via the [`Builder`] type,
|
||||||
//! which currently allows you to set the name and stack size for the child thread:
|
//! which currently allows you to set the name and stack size for the child thread:
|
||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```rust
|
||||||
@@ -88,43 +86,43 @@
|
|||||||
//!
|
//!
|
||||||
//! ## The `Thread` type
|
//! ## The `Thread` type
|
||||||
//!
|
//!
|
||||||
//! Threads are represented via the `Thread` type, which you can get in one of
|
//! Threads are represented via the [`Thread`] type, which you can get in one of
|
||||||
//! two ways:
|
//! two ways:
|
||||||
//!
|
//!
|
||||||
//! * By spawning a new thread, e.g. using the `thread::spawn` function, and
|
//! * By spawning a new thread, e.g. using the [`thread::spawn`][`spawn`]
|
||||||
//! calling `thread()` on the `JoinHandle`.
|
//! function, and calling [`thread()`] on the [`JoinHandle`].
|
||||||
//! * By requesting the current thread, using the `thread::current` function.
|
//! * By requesting the current thread, using the [`thread::current()`] function.
|
||||||
//!
|
//!
|
||||||
//! The `thread::current()` function is available even for threads not spawned
|
//! The [`thread::current()`] function is available even for threads not spawned
|
||||||
//! by the APIs of this module.
|
//! by the APIs of this module.
|
||||||
//!
|
//!
|
||||||
//! ## Blocking support: park and unpark
|
//! ## Blocking support: park and unpark
|
||||||
//!
|
//!
|
||||||
//! Every thread is equipped with some basic low-level blocking support, via the
|
//! Every thread is equipped with some basic low-level blocking support, via the
|
||||||
//! `thread::park()` function and `thread::Thread::unpark()` method. `park()`
|
//! [`thread::park()`][`park()`] function and [`thread::Thread::unpark()`][`unpark()`]
|
||||||
//! blocks the current thread, which can then be resumed from another thread by
|
//! method. [`park()`] blocks the current thread, which can then be resumed from
|
||||||
//! calling the `unpark()` method on the blocked thread's handle.
|
//! another thread by calling the [`unpark()`] method on the blocked thread's handle.
|
||||||
//!
|
//!
|
||||||
//! Conceptually, each `Thread` handle has an associated token, which is
|
//! Conceptually, each [`Thread`] handle has an associated token, which is
|
||||||
//! initially not present:
|
//! initially not present:
|
||||||
//!
|
//!
|
||||||
//! * The `thread::park()` function blocks the current thread unless or until
|
//! * The [`thread::park()`][`park()`] function blocks the current thread unless or until
|
||||||
//! the token is available for its thread handle, at which point it atomically
|
//! the token is available for its thread handle, at which point it atomically
|
||||||
//! consumes the token. It may also return *spuriously*, without consuming the
|
//! consumes the token. It may also return *spuriously*, without consuming the
|
||||||
//! token. `thread::park_timeout()` does the same, but allows specifying a
|
//! token. [`thread::park_timeout()`] does the same, but allows specifying a
|
||||||
//! maximum time to block the thread for.
|
//! maximum time to block the thread for.
|
||||||
//!
|
//!
|
||||||
//! * The `unpark()` method on a `Thread` atomically makes the token available
|
//! * The [`unpark()`] method on a [`Thread`] atomically makes the token available
|
||||||
//! if it wasn't already.
|
//! if it wasn't already.
|
||||||
//!
|
//!
|
||||||
//! In other words, each `Thread` acts a bit like a semaphore with initial count
|
//! In other words, each [`Thread`] acts a bit like a semaphore with initial count
|
||||||
//! 0, except that the semaphore is *saturating* (the count cannot go above 1),
|
//! 0, except that the semaphore is *saturating* (the count cannot go above 1),
|
||||||
//! and can return spuriously.
|
//! and can return spuriously.
|
||||||
//!
|
//!
|
||||||
//! The API is typically used by acquiring a handle to the current thread,
|
//! The API is typically used by acquiring a handle to the current thread,
|
||||||
//! placing that handle in a shared data structure so that other threads can
|
//! placing that handle in a shared data structure so that other threads can
|
||||||
//! find it, and then `park`ing. When some desired condition is met, another
|
//! find it, and then `park`ing. When some desired condition is met, another
|
||||||
//! thread calls `unpark` on the handle.
|
//! thread calls [`unpark()`] on the handle.
|
||||||
//!
|
//!
|
||||||
//! The motivation for this design is twofold:
|
//! The motivation for this design is twofold:
|
||||||
//!
|
//!
|
||||||
@@ -149,6 +147,22 @@
|
|||||||
//! will want to make use of some form of **interior mutability** through the
|
//! will want to make use of some form of **interior mutability** through the
|
||||||
//! [`Cell`] or [`RefCell`] types.
|
//! [`Cell`] or [`RefCell`] types.
|
||||||
//!
|
//!
|
||||||
|
//! [channels]: ../../std/sync/mpsc/index.html
|
||||||
|
//! [`Arc`]: ../../std/sync/struct.Arc.html
|
||||||
|
//! [`spawn`]: ../../std/thread/fn.spawn.html
|
||||||
|
//! [`JoinHandle`]: ../../std/thread/struct.JoinHandle.html
|
||||||
|
//! [`thread()`]: ../../std/thread/struct.JoinHandle.html#method.thread
|
||||||
|
//! [`join`]: ../../std/thread/struct.JoinHandle.html#method.join
|
||||||
|
//! [`Result`]: ../../std/result/enum.Result.html
|
||||||
|
//! [`Ok`]: ../../std/result/enum.Result.html#variant.Ok
|
||||||
|
//! [`Err`]: ../../std/result/enum.Result.html#variant.Err
|
||||||
|
//! [`panic!`]: ../../std/macro.panic.html
|
||||||
|
//! [`Builder`]: ../../std/thread/struct.Builder.html
|
||||||
|
//! [`thread::current()`]: ../../std/thread/fn.spawn.html
|
||||||
|
//! [`Thread`]: ../../std/thread/struct.Thread.html
|
||||||
|
//! [`park()`]: ../../std/thread/fn.park.html
|
||||||
|
//! [`unpark()`]: ../../std/thread/struct.Thread.html#method.unpark
|
||||||
|
//! [`thread::park_timeout()`]: ../../std/thread/fn.park_timeout.html
|
||||||
//! [`Cell`]: ../cell/struct.Cell.html
|
//! [`Cell`]: ../cell/struct.Cell.html
|
||||||
//! [`RefCell`]: ../cell/struct.RefCell.html
|
//! [`RefCell`]: ../cell/struct.RefCell.html
|
||||||
//! [`thread_local!`]: ../macro.thread_local.html
|
//! [`thread_local!`]: ../macro.thread_local.html
|
||||||
|
|||||||
Reference in New Issue
Block a user