| Crates.io | atomics |
| lib.rs | atomics |
| version | 0.3.3 |
| created_at | 2025-09-02 15:38:06.930994+00 |
| updated_at | 2025-10-21 10:19:34.381794+00 |
| description | Basic utils for concurrent programming. Backoff, spinlocks, seqlock, atomic type wrappers. |
| homepage | https://github.com/vdrn/atomics |
| repository | https://github.com/vdrn/atomics |
| max_upload_size | |
| id | 1821284 |
| size | 42,124 |
Basic utils for concurrent programming.
[dependencies]
atomics = "0.1"
Basic exponential backoff implementaiton.
thread::yield_now().hint::spin_loop() before it starts to thread::yield_now().hint::spin_loop() without ever yielding.Wrapps the type in atomic. Type size must match the size of the atomic.
Type must be Copy and have no uninit bytes.
new constructior is unsafe, since you need to guarantee that the type contains no uninit bytes.
With bytemuck feature, there is a safe constructor: new_no_uninit.
Alsmost the same as atomic_t::*, but uses atomic_maybe_uninit crate to support types that have uninit bytes.
This makes new constructor safe.
Downside is that atomic_maybe_uninit crate uses inline assembly to support this, which means you cannot use miri to test programs that use it.
SpinMutex used Backoff<6>.SpinSeqLockEx with a custom backoff param.SpinRwLock used Backoff<6>.SpinRwLockEx with a custom backoff param.Reference implementation: Amanieu/seqlock
SpinSeqLock used Backoff<6>.SpinSeqLockEx with a custom backoff param.Sequence locks support "optimistic reading" that can load() Copy types without writing to shared memory.
Downside is that "optimistic reading" is technically UB under Rust/C++ memory model. It is a well known "hole" in the model, but people have been using it in both Rust/C/C++ without issues (citation needed!).
Actual LLVM memory model allows for this use case, which might be part of the reason reason why things dont blow up.
Use it with caution!
NOTE: Since miri will recognize it as UB, optimistic reads are disabled for miri.
std - Enables thread::yield_now() for Backoff, otherwise it will awalys use just hint::spin_loop().serde - Enables Serialize and Deserialize for SpinSeqLock. TODO: support serde for other types!bytemuck - Enables safe constructor for atomic_t::* types.