#container #atomic #arc #box #monotonic

no-std quinine

Atomic monotonic containers (Mono{Box,Arc})

2 unstable releases

0.2.0 Feb 17, 2022
0.1.0 Feb 17, 2022

#970 in Concurrency

Download history 78/week @ 2024-07-21 90/week @ 2024-07-28 161/week @ 2024-08-04 63/week @ 2024-08-11 145/week @ 2024-08-18 53/week @ 2024-08-25 137/week @ 2024-09-01 75/week @ 2024-09-08 102/week @ 2024-09-15 190/week @ 2024-09-22 108/week @ 2024-09-29 246/week @ 2024-10-06 143/week @ 2024-10-13 228/week @ 2024-10-20 167/week @ 2024-10-27 142/week @ 2024-11-03

690 downloads per month
Used in verneuil

Apache-2.0/MIT

28KB
550 lines

Quinine

Crates.io docs.rs

Quinine implements atomic, lock-free, but write-once versions of containers like Option<Box<T>> (MonoBox) and Option<Arc<T>> (MonoArc).

These write-once containers can be read with mere Ordering::Acquire loads; reads otherwise perform like Box and Arc. On the write-side, atomic updates happen via compare-and-swaps, only the first of which will succeed.

The code is simpler (and likely faster) than, e.g., ArcSwap, because it exploits the monotonic nature of all updates to these write-once containers. That's particularly true for reads, but updates also avoid a lot of coordination overhead with potential concurrent readers.

When atomic containers can only transition monotonically from None to Some, and then stay there, we can implement simple update algorithms, without having to worry about the lifetime of references derived from the container: once we've observed Some value, the container can be trusted to keep it alive for us (until the container is dropped safely). The general form of this trick applies to any container that owns a monotonically increasing set of resources, until the container itself is destroyed.

No runtime deps

Features