Atom
This is an experimental implementation, meaning API might change and bugs might arise.
Experimental API for a synchronous and mutable smart-pointer type Atom<T> and its Weak<T> variant. Also includes the associated spin-lock type SpinLock.
Unlike Mutex<T>, Atom<T> does not use system futexes, but instead uses a simple spin-lock. This can be advantageous in cases of low contention i.e. when the lock is only held for a short time and there are few threads competing for the lock.
Usage
Atom<T> mimics the behavior of Arc<Mutex<T>>, but with a slightly different API. Instead
of lock-guards we simply access the inner T inside a closure.
let atom = new;
atom.lock;
assert_eq!;
We can access parts of the inner value and map parts of it to a new value:
let atom = new;
let sum: i32 = atom.map;
assert_eq!;
Or mutate and map:
let atom = new;
let three = atom.map_mut;
assert_eq!;
assert_eq!;
Example
use Atom;
Benchmarks
These tests we run on a AMD Ryzen 3 3100 4-Core Processor using the Criterion statistical benchmarking tool.
There are four different tests that simulate a real world scenario with a small thread count and low contention.
In the Balanced Read and Write and Read Heavy Read and Write we do a sort on a small vector and read the biggest value from the (reversed) vector.
In Write Only only test we do a sort and a reverse on a small vector.
In the Read Only test we do a find on a value in the vector.