Blazingly fast concurrent data structures for Rust applications.
Project details
Crossync delivers high-performance concurrent data structures tailored for Rust. With powerful atomic operations and synchronization primitives, it enables multithreaded applications to manage shared states seamlessly. Whether it's work queues or dynamic collections, Crossync provides essential tools for developers aiming for efficiency and reliability.
crossync is a robust library providing blazingly fast concurrent data structures for Rust, designed specifically for multithreaded applications. It leverages atomic operations, sophisticated backoff strategies, and internal locking mechanisms to ensure efficient shared access, making it a valuable resource for developers working with concurrency.
AtomicVec<T> is a thread-safe collection allowing concurrent push and pop operations. It utilizes block-based allocation and atomic indices to manage resources efficiently, making it ideal for work queues and dynamic collections.
Vec<T> by consuming its elements.use std::thread;
use crossync::atomic::AtomicVec;
let h = AtomicVec::new();
h.push("hello");
let b = h.clone();
drop(h);
{
let b = b.clone();
let t = thread::spawn(move || {
if let Some(v) = b.pop() {
assert_eq!(v, "hello");
}
});
t.join().unwrap();
}
assert!(b.pop().is_none());
AtomicHashMap<K, V> is a concurrent hash map supporting safe insertion and retrieval of key-value pairs.
use std::thread;
use crossync::atomic::AtomicHashMap;
let h = AtomicHashMap::new();
h.insert("c", "hello");
let b = h.clone();
drop(h);
{
let b = b.clone();
let t = thread::spawn(move || {
if let Some(mut v) = b.get_mut("c") {
*v = "world";
}
});
t.join().unwrap();
}
assert_eq!(b.get("c").unwrap(), "world");
AtomicBuffer<T> is a thread-safe ring buffer designed for concurrent producer-consumer scenarios with per-slot sequence numbers.
use crossync::atomic::AtomicBuffer;
use std::thread;
let buffer = AtomicBuffer::with_capacity(2);
let producer = {
let buffer = buffer.clone();
thread::spawn(move || {
buffer.push_box(Box::new(1)).unwrap();
buffer.push_box(Box::new(2)).unwrap();
})
};
let consumer = {
let buffer = buffer.clone();
thread::spawn(move || {
let mut count = 1;
while count <= 2 {
if let Some(value) = buffer.pop_box() {
assert_eq!(*value, count);
count += 1;
}
}
})
};
producer.join().unwrap();
consumer.join().unwrap();
The library also includes:
For further details on usage and implementation strategies, please refer to the README and additional documentation files.
Comments
0Start the conversation
Share the first comment.