#synchronization #thread-synchronization #sync

cond_sync

Hides the boilerplate code needed with std::sync::Condvar

2 releases

0.2.1 Sep 22, 2024
0.2.0 Sep 21, 2024

#549 in Concurrency

Download history 62/week @ 2024-09-24 39/week @ 2024-10-01 56/week @ 2024-10-08 42/week @ 2024-10-15 20/week @ 2024-10-22 29/week @ 2024-10-29 24/week @ 2024-11-05 2/week @ 2024-11-12 15/week @ 2024-11-19 10/week @ 2024-11-26 2/week @ 2024-12-03 27/week @ 2024-12-10 25/week @ 2024-12-17 23/week @ 2024-12-24 5/week @ 2025-01-07

55 downloads per month
Used in flexi_logger

MIT/Apache

14KB
198 lines

cond_sync

A thin wrapper around std::sync::CondVar and Mutex that enhances readability when synchronizing threads.

Latest version Documentation License Build unsafe forbidden

Usage

Add cond_sync to the dependencies in your project's Cargo.toml:

[dependencies]
cond_sync = "0.2"

Example

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();

// ...

Dependencies

No dependencies.

Versions

See the change log for more details.

No runtime deps