Crates.io | atomicbox |
lib.rs | atomicbox |
version | 0.4.0 |
source | src |
created_at | 2019-02-08 22:02:54.462886 |
updated_at | 2021-11-30 17:23:35.820052 |
description | Safe atomic pointers to boxed data. |
homepage | |
repository | https://github.com/jorendorff/atomicbox |
max_upload_size | |
id | 113606 |
size | 41,137 |
Safe atomic boxes.
This crate provides AtomicBox<T>
and AtomicOptionBox<T>
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!
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