Crate atomicslice

Source
Expand description

AtomicSlice<T> is a thread-safe wrapper around an array of arbitrary data which is just about as fast as possible to read while still being writable. Reading from an AtomicSlice<T> involves exactly three atomic operations (in release builds). Writing may involve some locking but is also possible from multiple threads.

AtomicSlice<T> is thus heavily optimized for the case of frequent reads from multiple threads with occasional updates from other threads.

The size of the internal array is arbitrary, but is fixed during construction.

Internally, AtomicSlice<T> allocates a pool of twice as much memory as requested, which is partioned into two halves. During typical usage, on of these is being read from exclusively while the other is available for writing. After a write, the two partitions switch roles and new readers being accessing the freshly-written data immediately, while existing readers guard access to the stale data until they are dropped.

Structsยง

AtomicSlice
A slice of data that can be written and read from multiple threads, which is heavily optimized for multiple concurrent reads and occasional writes.
AtomicSliceReadGuard
A smart pointer type representing read-only access to the data in an AtomicSlice. When this type is dropped, it will release the read lock on the AtomicSlice. In situations of high load where write throughput is also important, this lock should ideally not be held for very long.