Module std::thread_localExperimental
[-]
[+]
[src]
Thread local storage
This module provides an implementation of thread local storage for Rust programs. Thread local storage is a method of storing data into a global variable which each thread in the program will have its own copy of. Threads do not share this data, so accesses do not need to be synchronized.
At a high level, this module provides two variants of storage:
Owning thread local storage. This is a type of thread local key which owns the value that it contains, and will destroy the value when the thread exits. This variant is created with the
thread_local!macro and can contain any value which is'static(no borrowed pointers.Scoped thread local storage. This type of key is used to store a reference to a value into local storage temporarily for the scope of a function call. There are no restrictions on what types of values can be placed into this key.
Both forms of thread local storage provide an accessor function, with,
which will yield a shared reference to the value to the specified
closure. Thread local keys only allow shared access to values as there is no
way to guarantee uniqueness if a mutable borrow was allowed. Most values
will want to make use of some form of interior mutability through the
Cell or RefCell types.
Modules
| scoped | Scoped thread-local storage |
Structs
| Key | A thread local storage key which owns its contents. |
| OsStaticKey | A type for TLS keys that are statically allocated. |
Constants
| OS_INIT_INNER | Constant initialization value for the inner part of static TLS keys. |