Struct std::sys_common::thread_local_key::StaticKey[][src]

pub struct StaticKey {
    key: AtomicUsize,
    dtor: Option<unsafe extern "C" fn(_: *mut u8)>,
}
🔬 This is a nightly-only experimental API. (thread_local_internals)
Expand description

A type for TLS keys that are statically allocated.

This type is entirely unsafe to use as it does not protect against use-after-deallocation or use-during-deallocation.

The actual OS-TLS key is lazily allocated when this is used for the first time. The key is also deallocated when the Rust runtime exits or destroy is called, whichever comes first.

Examples

use tls::os::{StaticKey, INIT};

static KEY: StaticKey = INIT;

unsafe {
    assert!(KEY.get().is_null());
    KEY.set(1 as *mut u8);
}
Run

Fields

key: AtomicUsize
🔬 This is a nightly-only experimental API. (thread_local_internals)

Inner static TLS key (internals).

dtor: Option<unsafe extern "C" fn(_: *mut u8)>
🔬 This is a nightly-only experimental API. (thread_local_internals)

Destructor for the TLS value.

See Key::new for information about when the destructor runs and how it runs.

Implementations

🔬 This is a nightly-only experimental API. (thread_local_internals)
🔬 This is a nightly-only experimental API. (thread_local_internals)

Gets the value associated with this TLS key

This will lazily allocate a TLS key from the OS if one has not already been allocated.

🔬 This is a nightly-only experimental API. (thread_local_internals)

Sets this TLS key to a new value.

This will lazily allocate a TLS key from the OS if one has not already been allocated.

🔬 This is a nightly-only experimental API. (thread_local_internals)
🔬 This is a nightly-only experimental API. (thread_local_internals)

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.