Skip to main content

Module thread_safety

Module thread_safety 

Source
Expand description

§Thread Safety Primitives

Based on “Formal methods for the unsafe side of the Force” (Antithesis, 2026). Provides rigorously defined primitives for bridging FFI and multi-threaded boundaries.

§RelaxedAtomic<T>

Provides inner mutability for Copy types via relaxed atomic loads and stores. On x86_64 and ARM, relaxed loads/stores compile to the same instructions as regular memory accesses (no LOCK prefix), making this a zero-overhead way to achieve interior mutability for atomic-compatible types.

Deliberately omits fetch_* / CAS methods — those lower to bus-lock instructions that add noticeable overhead. Instead, use the load–mutate–store pattern:

let counter = RelaxedAtomic::new(0u32);
let val = counter.load();
counter.store(val + 1);

Structs§

MainThreadToken
A witness of execution that exists solely on a designated “Main Thread”.
RelaxedAtomic
Provides inner mutability for Copy types via relaxed atomic operations.
SendWrapper
A wrapper that allows sending non-Send types across thread boundaries.

Traits§

AtomicRepr
Trait for types that can be stored in a RelaxedAtomic.

Functions§

designate_main_thread
Designate the calling thread as the application’s main thread.
main_thread_id
Returns the ThreadId previously designated as the main thread, if any.