]>
git.proxmox.com Git - rustc.git/blob - vendor/crossbeam-utils/tests/wait_group.rs
1 extern crate crossbeam_utils
;
5 use std
::time
::Duration
;
7 use crossbeam_utils
::sync
::WaitGroup
;
9 const THREADS
: usize = 10;
13 let wg
= WaitGroup
::new();
14 let (tx
, rx
) = mpsc
::channel();
20 thread
::spawn(move || {
26 thread
::sleep(Duration
::from_millis(100));
28 // At this point, all spawned threads should be blocked, so we shouldn't get anything from the
30 assert
!(rx
.try_recv().is_err());
34 // Now, the wait group is cleared and we should receive messages.
42 let wg
= WaitGroup
::new();
43 let (tx
, rx
) = mpsc
::channel();
49 thread
::spawn(move || {
50 thread
::sleep(Duration
::from_millis(100));
56 // At this point, all spawned threads should be sleeping, so we shouldn't get anything from the
58 assert
!(rx
.try_recv().is_err());
62 // Now, the wait group is cleared and we should receive messages.
64 rx
.try_recv().unwrap();