Skip to content

Commit 8f96630

Browse files
committed
---
yaml --- r: 88843 b: refs/heads/snap-stage3 c: 780afea h: refs/heads/master i: 88841: 579f3a2 88839: 3fd9ebe v: v3
1 parent d9b5ecc commit 8f96630

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: deeca5d586bfaa4aa60246f671a8d611d38f6248
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 7554f5c58f840b648bc3c5b2d24d0df6683eed03
4+
refs/heads/snap-stage3: 780afeaf0a2c063c68d91660eb15a3314f1eadcb
55
refs/heads/try: b160761e35efcd1207112b3b782c06633cf441a8
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libstd/rt/thread.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub struct Thread<T> {
3333
priv packet: ~Option<T>,
3434
}
3535

36-
static DEFAULT_STACK_SIZE: libc::size_t = 1024 * 1024;
36+
static DEFAULT_STACK_SIZE: uint = 1024 * 1024;
3737

3838
// This is the starting point of rust os threads. The first thing we do
3939
// is make sure that we don't trigger __morestack (also why this has a
@@ -84,7 +84,7 @@ impl Thread<()> {
8484
*cast::transmute::<&~Option<T>, **mut Option<T>>(&packet)
8585
};
8686
let main: proc() = proc() unsafe { *packet2 = Some(main()); };
87-
let native = unsafe { imp::create(~main) };
87+
let native = unsafe { imp::create(stack, ~main) };
8888

8989
Thread {
9090
native: native,
@@ -100,8 +100,14 @@ impl Thread<()> {
100100
/// systems. Note that platforms may not keep the main program alive even if
101101
/// there are detached thread still running around.
102102
pub fn spawn(main: proc()) {
103+
Thread::spawn_stack(DEFAULT_STACK_SIZE, main)
104+
}
105+
106+
/// Performs the same functionality as `spawn`, but explicitly specifies a
107+
/// stack size for the new thread.
108+
pub fn spawn_stack(stack: uint, main: proc()) {
103109
unsafe {
104-
let handle = imp::create(~main);
110+
let handle = imp::create(stack, ~main);
105111
imp::detach(handle);
106112
}
107113
}
@@ -145,13 +151,15 @@ mod imp {
145151
use libc::types::os::arch::extra::{LPSECURITY_ATTRIBUTES, SIZE_T, BOOL,
146152
LPVOID, DWORD, LPDWORD, HANDLE};
147153
use ptr;
154+
use libc;
155+
use cast;
148156

149157
pub type rust_thread = HANDLE;
150158
pub type rust_thread_return = DWORD;
151159

152-
pub unsafe fn create(p: ~proc()) -> rust_thread {
160+
pub unsafe fn create(stack: uint, p: ~proc()) -> rust_thread {
153161
let arg: *mut libc::c_void = cast::transmute(p);
154-
CreateThread(ptr::mut_null(), DEFAULT_STACK_SIZE, super::thread_start,
162+
CreateThread(ptr::mut_null(), stack as libc::size_t, super::thread_start,
155163
arg, 0, ptr::mut_null())
156164
}
157165

@@ -189,17 +197,17 @@ mod imp {
189197
use libc::consts::os::posix01::PTHREAD_CREATE_JOINABLE;
190198
use libc;
191199
use ptr;
192-
use super::DEFAULT_STACK_SIZE;
193200
use unstable::intrinsics;
194201

195202
pub type rust_thread = libc::pthread_t;
196203
pub type rust_thread_return = *libc::c_void;
197204

198-
pub unsafe fn create(p: ~proc()) -> rust_thread {
205+
pub unsafe fn create(stack: uint, p: ~proc()) -> rust_thread {
199206
let mut native: libc::pthread_t = intrinsics::uninit();
200207
let mut attr: libc::pthread_attr_t = intrinsics::uninit();
201208
assert_eq!(pthread_attr_init(&mut attr), 0);
202-
assert_eq!(pthread_attr_setstacksize(&mut attr, DEFAULT_STACK_SIZE), 0);
209+
assert_eq!(pthread_attr_setstacksize(&mut attr,
210+
stack as libc::size_t), 0);
203211
assert_eq!(pthread_attr_setdetachstate(&mut attr,
204212
PTHREAD_CREATE_JOINABLE), 0);
205213

0 commit comments

Comments
 (0)