File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -228,3 +228,35 @@ fn broadcast_sleep_race() {
228
228
} ) ;
229
229
}
230
230
}
231
+
232
+ #[ test]
233
+ fn broadcast_after_spawn_broadcast ( ) {
234
+ let ( tx, rx) = crossbeam_channel:: unbounded ( ) ;
235
+
236
+ // Queue a non-blocking spawn_broadcast.
237
+ crate :: spawn_broadcast ( move |ctx| tx. send ( ctx. index ( ) ) . unwrap ( ) ) ;
238
+
239
+ // This blocking broadcast runs after all prior broadcasts.
240
+ crate :: broadcast ( |_| { } ) ;
241
+
242
+ // The spawn_broadcast **must** have run by now on all threads.
243
+ let mut v: Vec < _ > = rx. try_iter ( ) . collect ( ) ;
244
+ v. sort_unstable ( ) ;
245
+ assert ! ( v. into_iter( ) . eq( 0 ..crate :: current_num_threads( ) ) ) ;
246
+ }
247
+
248
+ #[ test]
249
+ fn broadcast_after_spawn ( ) {
250
+ let ( tx, rx) = crossbeam_channel:: bounded ( 1 ) ;
251
+
252
+ // Queue a regular spawn on a thread-local deque.
253
+ crate :: registry:: in_worker ( move |_, _| {
254
+ crate :: spawn ( move || tx. send ( 22 ) . unwrap ( ) ) ;
255
+ } ) ;
256
+
257
+ // Broadcast runs after the local deque is empty.
258
+ crate :: broadcast ( |_| { } ) ;
259
+
260
+ // The spawn **must** have run by now.
261
+ assert_eq ! ( 22 , rx. try_recv( ) . unwrap( ) ) ;
262
+ }
You can’t perform that action at this time.
0 commit comments