crossync is a Rust library for concurrent data structures and synchronization.
The library has thread-safe collections, a multi-producer, multi-consumer (MPMC) channel, and reader-writer locks.
Run this command in your Cargo project.
cargo add crossyncThis example uses AtomicVec to add values from two threads.
The cloned handle gives both threads access to the same collection.
use crossync::atomic::AtomicVec;
use std::thread;
let values = AtomicVec::new();
let worker_values = values.clone();
let worker = thread::spawn(move || worker_values.push(2));
values.push(1);
worker.join().unwrap();
assert_eq!(values.len(), 2);| Type | Use |
|---|---|
AtomicVec |
Add and remove elements in a concurrent vector. |
AtomicArray |
Read or change values by index in a fixed-capacity array. |
AtomicHashMap |
Store key-value pairs in a concurrent hash map. |
AtomicBuffer |
Transfer boxed values through a bounded ring buffer. |
Atomic and AtomicCell |
Control access to one value. |
Mpmc |
Send messages through a bounded or unbounded channel. |
RwLock and SpinCell |
Give access to multiple readers or one writer. |
Barrier |
Make threads wait at a phase boundary. |
- Rust API reference
- Rust concurrency examples
- Concurrency and ownership guide
- Rust concurrency benchmarks
- Changelog
crossync uses the Apache License 2.0.