]>
git.proxmox.com Git - rustc.git/blob - src/libstd/sys_common/thread.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 use alloc
::boxed
::FnBox
;
13 use sync
::atomic
::{self, Ordering}
;
14 use sys
::stack_overflow
;
15 use sys
::thread
as imp
;
18 pub unsafe fn start_thread(main
: *mut u8) {
19 // Next, set up our stack overflow handler which may get triggered if we run
21 let _handler
= stack_overflow
::Handler
::new();
23 // Finally, let's run some code.
24 Box
::from_raw(main
as *mut Box
<FnBox()>)()
27 pub fn min_stack() -> usize {
28 static MIN
: atomic
::AtomicUsize
= atomic
::AtomicUsize
::new(0);
29 match MIN
.load(Ordering
::SeqCst
) {
33 let amt
= env
::var("RUST_MIN_STACK").ok().and_then(|s
| s
.parse().ok());
34 let amt
= amt
.unwrap_or(imp
::DEFAULT_MIN_STACK_SIZE
);
36 // 0 is our sentinel value, so ensure that we'll never see 0 after
37 // initialization has run
38 MIN
.store(amt
+ 1, Ordering
::SeqCst
);