@@ -4,10 +4,11 @@ use crate::mem;
4
4
use crate :: panic:: panic_any;
5
5
use crate :: result;
6
6
use crate :: sync:: {
7
+ atomic:: { AtomicBool , Ordering } ,
7
8
mpsc:: { channel, Sender } ,
8
9
Arc , Barrier ,
9
10
} ;
10
- use crate :: thread:: { self , ThreadId } ;
11
+ use crate :: thread:: { self , Scope , ThreadId } ;
11
12
use crate :: time:: Duration ;
12
13
use crate :: time:: Instant ;
13
14
@@ -293,3 +294,25 @@ fn test_thread_id_not_equal() {
293
294
assert ! ( thread:: current( ) . id( ) != spawned_id) ;
294
295
}
295
296
297
+ #[ test]
298
+ fn test_scoped_threads_drop_result_before_join ( ) {
299
+ let actually_finished = & AtomicBool :: new ( false ) ;
300
+ struct X < ' scope , ' env > ( & ' scope Scope < ' scope , ' env > , & ' env AtomicBool ) ;
301
+ impl Drop for X < ' _ , ' _ > {
302
+ fn drop ( & mut self ) {
303
+ thread:: sleep ( Duration :: from_millis ( 20 ) ) ;
304
+ let actually_finished = self . 1 ;
305
+ self . 0 . spawn ( move || {
306
+ thread:: sleep ( Duration :: from_millis ( 20 ) ) ;
307
+ actually_finished. store ( true , Ordering :: Relaxed ) ;
308
+ } ) ;
309
+ }
310
+ }
311
+ thread:: scope ( |s| {
312
+ s. spawn ( move || {
313
+ thread:: sleep ( Duration :: from_millis ( 20 ) ) ;
314
+ X ( s, actually_finished)
315
+ } ) ;
316
+ } ) ;
317
+ assert ! ( actually_finished. load( Ordering :: Relaxed ) ) ;
318
+ }
0 commit comments