diff options
| author | bors <bors@rust-lang.org> | 2015-04-22 18:48:31 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-04-22 18:48:31 +0000 |
| commit | 5c9636975cdc289e98ef8f33400969371c4ce1bf (patch) | |
| tree | 28e75d58061a77b9a1d6c6f3c0853473c52169c5 /src/libstd/sys/common | |
| parent | 3dbfa74305e6cc347ffdd902a680bb3b9ee2470a (diff) | |
| parent | 2e1100997863c4951371cf39554c53266cacb37d (diff) | |
| download | rust-5c9636975cdc289e98ef8f33400969371c4ce1bf.tar.gz rust-5c9636975cdc289e98ef8f33400969371c4ce1bf.zip | |
Auto merge of #24447 - alexcrichton:audit-thread, r=aturon
Much of this code hasn't been updated in quite some time and this commit does a small audit of the functionality: * Implementation functions now centralize all functionality on a locally defined `Thread` type. * The `detach` method has been removed in favor of a `Drop` implementation. This notably fixes leaking thread handles on Windows. * The `Thread` structure is now appropriately annotated with `Send` and `Sync` automatically on Windows and in a custom fashion on Unix. * The unsafety of creating a thread has been pushed out to the right boundaries now. Closes #24442
Diffstat (limited to 'src/libstd/sys/common')
| -rw-r--r-- | src/libstd/sys/common/thread.rs | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/libstd/sys/common/thread.rs b/src/libstd/sys/common/thread.rs index 1845b6266ed..d19ef11c01f 100644 --- a/src/libstd/sys/common/thread.rs +++ b/src/libstd/sys/common/thread.rs @@ -10,22 +10,22 @@ use prelude::v1::*; -use usize; +use alloc::boxed::FnBox; use libc; -use thunk::Thunk; -use sys_common::stack; use sys::stack_overflow; +use sys_common::stack; +use usize; -// This is the starting point of rust os threads. The first thing we do -// is make sure that we don't trigger __morestack (also why this has a -// no_stack_check annotation), and then we extract the main function -// and invoke it. #[no_stack_check] -pub fn start_thread(main: *mut libc::c_void) { - unsafe { - stack::record_os_managed_stack_bounds(0, usize::MAX); - let _handler = stack_overflow::Handler::new(); - let main: Box<Thunk> = Box::from_raw(main as *mut Thunk); - main(); - } +pub unsafe fn start_thread(main: *mut libc::c_void) { + // First ensure that we don't trigger __morestack (also why this has a + // no_stack_check annotation). + stack::record_os_managed_stack_bounds(0, usize::MAX); + + // Next, set up our stack overflow handler which may get triggered if we run + // out of stack. + let _handler = stack_overflow::Handler::new(); + + // Finally, let's run some code. + Box::from_raw(main as *mut Box<FnBox()>)() } |
