| Crates.io | cond_sync |
| lib.rs | cond_sync |
| version | 0.2.1 |
| created_at | 2024-09-21 09:41:11.186072+00 |
| updated_at | 2024-09-22 08:33:48.866453+00 |
| description | Hides the boilerplate code needed with std::sync::Condvar |
| homepage | |
| repository | https://github.com/emabee/cond_sync |
| max_upload_size | |
| id | 1382090 |
| size | 25,222 |
A thin wrapper around std::sync::CondVar and Mutex that enhances readability when synchronizing threads.
Add cond_sync to the dependencies in your project's Cargo.toml:
[dependencies]
cond_sync = "0.2"
use cond_sync::{CondSync, Other};
let cond_sync = CondSync::new(0_usize);
for i in 0..5 {
let cond_sync_t = cond_sync.clone();
std::thread::spawn(move || {
// ...initialize...
cond_sync_t.modify_and_notify(|v| *v += 1, Other::One).unwrap();
// ...do real work...
});
}
// wait until all threads are initialized
cond_sync.wait_until(|v| *v == 5).unwrap();
// ...
No dependencies.
See the change log for more details.