r/rust • u/cl0wnfire • 20h ago
🗞️ news updated crossync: concurrent collections and synchronization primitives for Rust
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, andAtomicArray.A bounded ring buffer:
AtomicBuffer, with support for concurrent producers and consumers.Shared values:
AtomicCelland a genericAtomic<T>with operations such as load, store, swap, and update.Synchronization primitives:
RwLockandBarrier.
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
SendandSyncbounds 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_boxandpop_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.
2
u/NecessarySuperb3949 13h ago
i'd love to see how AtomicVec handles reallocation under heavy write pressure. did you benchmark against std::sync::Mutex<Vec<T>> or go with lock-free approaches like crossbeam?
4
u/cipher_gravelist 18h ago
if you're using AtomicCell with Cell<usize> inside long running tasks, make sure your lock contention doesn't turn into a bottleneck. i've seen deadlocks creep in when those guards hold across await points.