#group

sync-wait-group

Wait group for synchronizing the beginning or end of some computation

2 releases

0.1.1 Jul 7, 2022
0.1.0 Apr 27, 2022

#147 in #group


Used in tender

MIT/Apache

8KB
111 lines

sync-wait-group

Crate API

License: Apache OR License: MIT

Wait group for synchronizing the beginning or end of some computation.

This crate is duplicated WaitGroup from crossbeam_utils::sync::WaitGroup, but use parking_lot::{Mutex, Condvar} instead of std::sync::{Mutex, Condvar}.

Example

use sync_wait_group::WaitGroup;
use std::thread;

// Create a new wait group.
let wg = WaitGroup::new();

for _ in 0..4 {
    // Create another reference to the wait group.
    let wg = wg.clone();

    thread::spawn(move || {
        // Do some work.

        // Drop the reference to the wait group.
        drop(wg);
    });
}

// Block until all threads have finished their work.
wg.wait();

Rust Version

This version of sync-wait-group requires Rust 1.56 or later.

License

Dual-licensed to be compatible with the Rust project.

Licensed under the Apache License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0 or the MIT license http://opensource.org/licenses/MIT, at your option. This file may not be copied, modified, or distributed except according to those terms.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in sync-wait-group by you, shall be licensed as Apache-2.0 and MIT, without any additional terms or conditions.

Dependencies

~0.4–5MB
~11K SLoC