@@ -4,10 +4,11 @@ use crate::mem;
44use crate :: panic:: panic_any;
55use crate :: result;
66use crate :: sync:: {
7+ atomic:: { AtomicBool , Ordering } ,
78 mpsc:: { channel, Sender } ,
89 Arc , Barrier ,
910} ;
10- use crate :: thread:: { self , ThreadId } ;
11+ use crate :: thread:: { self , Scope , ThreadId } ;
1112use crate :: time:: Duration ;
1213use crate :: time:: Instant ;
1314
@@ -293,3 +294,25 @@ fn test_thread_id_not_equal() {
293294 assert ! ( thread:: current( ) . id( ) != spawned_id) ;
294295}
295296
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