Module std::thread_local::scopedExperimental
[-]
[+]
[src]
Scoped thread-local storage
This module provides the ability to generate scoped thread-local variables. In this sense, scoped indicates that thread local storage actually stores a reference to a value, and this reference is only placed in storage for a scoped amount of time.
There are no restrictions on what types can be placed into a scoped variable, but all scoped variables are initialized to the equivalent of null. Scoped thread local storage is useful when a value is present for a known period of time and it is not required to relinquish ownership of the contents.
Example
fn main() { scoped_thread_local!(static FOO: uint); // Initially each scoped slot is empty. assert!(!FOO.is_set()); // When inserting a value, the value is only in place for the duration // of the closure specified. FOO.set(&1, || { FOO.with(|slot| { assert_eq!(*slot, 1); }); }); }scoped_thread_local!(static FOO: uint); // Initially each scoped slot is empty. assert!(!FOO.is_set()); // When inserting a value, the value is only in place for the duration // of the closure specified. FOO.set(&1, || { FOO.with(|slot| { assert_eq!(*slot, 1); }); });
Structs
Key | Type representing a thread local storage key corresponding to a reference
to the type parameter |
Constants
OS_INIT | Constant initialization value for static TLS keys. |