|
135 | 135 | //! |
136 | 136 | //! ## Thread-local storage |
137 | 137 | //! |
138 | | -//! This module also provides an implementation of thread local storage for Rust |
139 | | -//! programs. Thread local storage is a method of storing data into a global |
140 | | -//! variable which each thread in the program will have its own copy of. |
| 138 | +//! This module also provides an implementation of thread-local storage for Rust |
| 139 | +//! programs. Thread-local storage is a method of storing data into a global |
| 140 | +//! variable that each thread in the program will have its own copy of. |
141 | 141 | //! Threads do not share this data, so accesses do not need to be synchronized. |
142 | 142 | //! |
143 | | -//! At a high level, this module provides two variants of storage: |
144 | | -//! |
145 | | -//! * Owned thread-local storage. This is a type of thread local key which |
146 | | -//! owns the value that it contains, and will destroy the value when the |
147 | | -//! thread exits. This variant is created with the `thread_local!` macro and |
148 | | -//! can contain any value which is `'static` (no borrowed pointers). |
149 | | -//! |
150 | | -//! * Scoped thread-local storage. This type of key is used to store a reference |
151 | | -//! to a value into local storage temporarily for the scope of a function |
152 | | -//! call. There are no restrictions on what types of values can be placed |
153 | | -//! into this key. |
154 | | -//! |
155 | | -//! Both forms of thread local storage provide an accessor function, `with`, |
156 | | -//! which will yield a shared reference to the value to the specified |
157 | | -//! closure. Thread-local keys only allow shared access to values as there is no |
158 | | -//! way to guarantee uniqueness if a mutable borrow was allowed. Most values |
| 143 | +//! A thread-local key owns the value it contains and will destroy the value when the |
| 144 | +//! thread exits. It is created with the [`thread_local!`] macro and can contain any |
| 145 | +//! value that is `'static` (no borrowed pointers). It provides an accessor function, |
| 146 | +//! [`with`], that yields a shared reference to the value to the specified |
| 147 | +//! closure. Thread-local keys allow only shared access to values, as there would be no |
| 148 | +//! way to guarantee uniqueness if mutable borrows were allowed. Most values |
159 | 149 | //! will want to make use of some form of **interior mutability** through the |
160 | | -//! `Cell` or `RefCell` types. |
| 150 | +//! [`Cell`] or [`RefCell`] types. |
| 151 | +//! |
| 152 | +//! [`Cell`]: ../cell/struct.Cell.html |
| 153 | +//! [`RefCell`]: ../cell/struct.RefCell.html |
| 154 | +//! [`thread_local!`]: ../macro.thread_local!.html |
| 155 | +//! [`with`]: struct.LocalKey.html#method.with |
161 | 156 |
|
162 | 157 | #![stable(feature = "rust1", since = "1.0.0")] |
163 | 158 |
|
|
0 commit comments