diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-04-14 22:13:57 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-04-22 10:42:33 -0700 |
| commit | 2e1100997863c4951371cf39554c53266cacb37d (patch) | |
| tree | e4d266578d80fa55705ba349c4508191fd5a692b /src/libstd/sys/common | |
| parent | e9e9279d87d5786fcb8e12482f2920979602267b (diff) | |
| download | rust-2e1100997863c4951371cf39554c53266cacb37d.tar.gz rust-2e1100997863c4951371cf39554c53266cacb37d.zip | |
std: Audit std::thread implementations
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()>)() } |
