Module thread_local

Source
๐Ÿ”ฌThis is a nightly-only experimental API. (thread_local_internals)
Expand description

Implementation of the thread_local macro.

There are three different thread-local implementations:

  • Some targets lack threading support, and hence have only one thread, so the TLS data is stored in a normal static.
  • Some targets support TLS natively via the dynamic linker and C runtime.
  • On some targets, the OS provides a library-based TLS implementation. The TLS data is heap-allocated and referenced using a TLS key.

Each implementation provides a macro which generates the LocalKey const used to reference the TLS variable, along with the necessary helper structs to track the initialization/destruction state of the variable.

Additionally, this module contains abstractions for the OS interfaces used for these implementations.

Re-exportsยง

pub use native::EagerStorage;Experimental
pub use native::LazyStorage;Experimental
pub use native::thread_local_inner;Experimental

Modulesยง

destructors ๐Ÿ”’ Experimental
The native TLS implementation needs a way to register destructors for its data. This module contains platform-specific implementations of that register.
guard ๐Ÿ”’ Experimental
This module provides a way to schedule the execution of the destructor list and the runtime cleanup function. Calling enable should ensure that these functions are called at the right times.
key ๐Ÿ”’ Experimental
const-creatable TLS keys.
native ๐Ÿ”’ Experimental
Thread local support for platforms with native TLS.

Functionsยง

abort_on_dtor_unwind ๐Ÿ”’ Experimental
Run a callback in a scenario which must not unwind (such as a extern "C" fn declared in a user crate). If the callback unwinds anyway, then rtabort with a message about thread local panicking on drop.