File tree Expand file tree Collapse file tree 3 files changed +32
-1
lines changed
tests/ui/threads-sendsync Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -736,7 +736,7 @@ pub mod guard {
736
736
target_os = "netbsd" ,
737
737
target_os = "l4re"
738
738
) ) ]
739
- unsafe fn get_stack_start ( ) -> Option < * mut libc:: c_void > {
739
+ pub ( crate ) unsafe fn get_stack_start ( ) -> Option < * mut libc:: c_void > {
740
740
let mut ret = None ;
741
741
let mut attr: libc:: pthread_attr_t = crate :: mem:: zeroed ( ) ;
742
742
#[ cfg( target_os = "freebsd" ) ]
Original file line number Diff line number Diff line change 158
158
#[ cfg( all( test, not( target_os = "emscripten" ) ) ) ]
159
159
mod tests;
160
160
161
+ use crate :: alloc:: GcAllocator ;
161
162
use crate :: any:: Any ;
162
163
use crate :: cell:: UnsafeCell ;
163
164
use crate :: ffi:: { CStr , CString } ;
@@ -517,6 +518,15 @@ impl Builder {
517
518
imp:: Thread :: set_name ( name) ;
518
519
}
519
520
521
+ // SAFETY: Register the thread with libgc so that its stack can be scanned
522
+ // for garbage collection.
523
+ let stack_start = unsafe { imp:: guard:: get_stack_start ( ) . unwrap ( ) } ;
524
+ if stack_start != crate :: ptr:: null_mut ( ) {
525
+ unsafe {
526
+ GcAllocator :: register_thread ( & stack_start as * const _ as * mut u8 ) ;
527
+ }
528
+ }
529
+
520
530
crate :: io:: set_output_capture ( output_capture) ;
521
531
522
532
// SAFETY: we constructed `f` initialized.
@@ -528,6 +538,12 @@ impl Builder {
528
538
let try_result = panic:: catch_unwind ( panic:: AssertUnwindSafe ( || {
529
539
crate :: sys_common:: backtrace:: __rust_begin_short_backtrace ( f)
530
540
} ) ) ;
541
+
542
+ // SAFETY: The thread has no more work to do, so can be unregisterd.
543
+ unsafe {
544
+ GcAllocator :: unregister_thread ( ) ;
545
+ }
546
+
531
547
// SAFETY: `their_packet` as been built just above and moved by the
532
548
// closure (it is an Arc<...>) and `my_packet` will be stored in the
533
549
// same `JoinInner` as this closure meaning the mutation will be
Original file line number Diff line number Diff line change
1
+ // run-pass
2
+ // ignore-emscripten no threads support
3
+ #![ feature( rustc_private) ]
4
+
5
+ use std:: alloc:: GcAllocator ;
6
+ use std:: thread;
7
+
8
+ pub fn main ( ) {
9
+ let res = thread:: spawn ( child) . join ( ) . unwrap ( ) ;
10
+ assert ! ( res) ;
11
+ }
12
+
13
+ fn child ( ) -> bool {
14
+ GcAllocator :: thread_registered ( )
15
+ }
You can’t perform that action at this time.
0 commit comments