https://github.com/jorendorff/atomicbox
Safe atomic Box types for Rust
https://github.com/jorendorff/atomicbox
atomics concurrency rust
Last synced: 9 months ago
JSON representation
Safe atomic Box types for Rust
- Host: GitHub
- URL: https://github.com/jorendorff/atomicbox
- Owner: jorendorff
- License: other
- Created: 2016-09-18T23:43:15.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2023-01-13T15:24:05.000Z (almost 3 years ago)
- Last Synced: 2025-03-30T11:12:03.857Z (10 months ago)
- Topics: atomics, concurrency, rust
- Language: Rust
- Size: 46.9 KB
- Stars: 22
- Watchers: 2
- Forks: 11
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# atomicbox
**Safe atomic boxes.**
[](https://docs.rs/atomicbox)
[](https://crates.io/crates/atomicbox)
[](https://crates.io/crates/atomicbox)
[](https://github.com/jorendorff/atomicbox/actions?query=workflow%3Aci)
This crate provides `AtomicBox` and `AtomicOptionBox` types: safe, owning
versions of the standard library's `AtomicPtr`.
Unfortunately, the only operations you can perform on an atomic box are
swaps and stores: you can't just use the box without taking ownership of it.
Imagine a `Box` without `Deref` or `DerefMut` implementations, and you'll
get the idea. Still, this is sufficient for some lock-free data structures,
so here it is!
### Why no `Deref`?
It wouldn't be safe. The point of an `AtomicBox` is that other threads can
obtain the boxed value, take ownership of it, even drop it, all without
taking a lock. So there is no safe way to borrow that value—except to swap
it out of the `AtomicBox` yourself.
This is pretty much the same reason you can't borrow a reference to the
contents of any other atomic type. It would invite data races. The only
difference here is that those contents happen to be on the heap.
License: MIT/Apache-2.0