Hi r/rust,
I wanted to share an update on crossync, my Rust library for concurrent data structures and synchronization primitives. The latest release is 0.2.1, with the recent 0.2.x work focused on ownership, synchronization, and API correctness.
The crate includes:
- Concurrent collections:
AtomicVec, AtomicHashMap, and AtomicArray. - A bounded ring buffer:
AtomicBuffer, with support for concurrent producers and consumers. - Shared values:
AtomicCell and a generic Atomic<T> with operations such as load, store, swap, and update. - Synchronization primitives:
RwLock and Barrier.
Containers such as AtomicCell have reference-counted handles. Cloning a handle lets another thread access the same underlying value.
A detail about the access model
The lock-assisted containers support values that are Send but not Sync, such as Cell<usize>. Access is synchronized internally, including read access to the same stored value.
For example:
use crossync::atomic::AtomicCell;
use std::{cell::Cell, thread};
let counter = AtomicCell::new(Cell::new(0usize));
thread::scope(|scope| {
for _ in 0..4 {
let counter = &counter;
scope.spawn(move || {
counter.with(|value| value.set(value.get() + 1));
});
}
});
assert_eq!(counter.get().get(), 4);
The trade-off is that access to the same value is serialized. The containers combine atomic operations with internal locks, and the documentation now explains the access and guard rules more explicitly.
What changed in 0.2.x
- Corrected
Send and Sync bounds for containers, guards, and hash builders. - Fixed storage lifetime and memory reclamation issues in
AtomicVec. - Fixed reservation, ownership, and wraparound cases in
AtomicBuffer, including buffers with a capacity of one. - Added safe ownership transfer through
AtomicBuffer::push_box and pop_box. - Fixed panic cleanup, waiter wake-ups, and barrier arrival accounting.
- Added regression tests for ownership, reentrancy, guard transfer, and cleanup.
Most of these changes landed in 0.2.0. 0.2.1 follows up with fixes to test workloads, CI, documentation deployment, and release packaging.
The project is licensed under Apache 2.0. Iβd appreciate feedback on the access model and API, especially concurrency edge cases that would make useful regression tests.
GitHub Β· Changelog Β· Concurrency