File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change 41
41
for i in 0 ..iters {
42
42
push( & mut p, i as u8 ) ;
43
43
}
44
- let barrier = Arc :: new( Barrier :: new( 2 ) ) ;
44
+ let barrier = Arc :: new( Barrier :: new( 3 ) ) ;
45
45
let push_thread = {
46
46
let barrier = Arc :: clone( & barrier) ;
47
47
std:: thread:: spawn( move || {
55
55
( start_pushing, stop_pushing)
56
56
} )
57
57
} ;
58
+ let trigger_thread = {
59
+ let barrier = Arc :: clone( & barrier) ;
60
+ std:: thread:: spawn( move || {
61
+ // Try to force other threads to go to sleep on barrier.
62
+ std:: thread:: yield_now( ) ;
63
+ std:: thread:: yield_now( ) ;
64
+ std:: thread:: yield_now( ) ;
65
+ barrier. wait( ) ;
66
+ // Hopefully, the other two threads now wake up at the same time.
67
+ } )
68
+ } ;
58
69
barrier. wait( ) ;
59
70
let start_popping = std:: time:: Instant :: now( ) ;
60
71
for _ in 0 ..iters {
61
72
black_box( pop( & mut c) ) ;
62
73
}
63
74
let stop_popping = std:: time:: Instant :: now( ) ;
64
75
let ( start_pushing, stop_pushing) = push_thread. join( ) . unwrap( ) ;
76
+ trigger_thread. join( ) . unwrap( ) ;
65
77
let total = stop_pushing
66
78
. max( stop_popping)
67
79
. duration_since( start_pushing. min( start_popping) ) ;
You can’t perform that action at this time.
0 commit comments