[−][src]Crate msp430_atomic
Atomic types
Atomic types provide primitive shared-memory communication between threads, and are the building blocks of other concurrent types.
This module defines atomic versions of a select number of primitive
types, including AtomicBool
, AtomicIsize
, and AtomicUsize
.
Atomic types present operations that, when used correctly, synchronize
updates between threads.
MSP430 note: All atomic operations in this crate have SeqCst
memory ordering.
Atomic variables are safe to share between threads (they implement Sync
)
but they do not themselves provide the mechanism for sharing and follow the
threading model
of rust.
Most atomic types may be stored in static variables, initialized using
the provided static initializers like ATOMIC_BOOL_INIT
. Atomic statics
are often used for lazy global initialization.
Examples
A simple spinlock:
use msp430_atomic::{AtomicUsize, ATOMIC_USIZE_INIT}; use std::thread; // Initialize SPINLOCK to 0 static SPINLOCK: AtomicUsize = ATOMIC_USIZE_INIT; fn main() { let thread = thread::spawn(move|| { SPINLOCK.store(1); }); // Wait for the other thread to release the lock while SPINLOCK.load() == 0 {} if let Err(panic) = thread.join() { println!("Thread had an error: {:?}", panic); } }
Structs
AtomicBool | A boolean type which can be safely shared between threads. |
AtomicI8 | An integer type which can be safely shared between threads. |
AtomicI16 | An integer type which can be safely shared between threads. |
AtomicIsize | An integer type which can be safely shared between threads. |
AtomicPtr | A raw pointer type which can be safely shared between threads. |
AtomicU8 | An integer type which can be safely shared between threads. |
AtomicU16 | An integer type which can be safely shared between threads. |
AtomicUsize | An integer type which can be safely shared between threads. |
Constants
ATOMIC_BOOL_INIT | An |
ATOMIC_I8_INIT | An atomic integer initialized to |
ATOMIC_I16_INIT | An atomic integer initialized to |
ATOMIC_ISIZE_INIT | An atomic integer initialized to |
ATOMIC_U8_INIT | An atomic integer initialized to |
ATOMIC_U16_INIT | An atomic integer initialized to |
ATOMIC_USIZE_INIT | An atomic integer initialized to |
Traits
AtomicOperations | Atomic arithmetic and bitwise operations implemented for numerical types. Each operation is implemented with a single assembly instruction. |