@@ -33,7 +33,7 @@ pub struct Thread<T> {
33
33
priv packet : ~Option < T > ,
34
34
}
35
35
36
- static DEFAULT_STACK_SIZE : libc :: size_t = 1024 * 1024 ;
36
+ static DEFAULT_STACK_SIZE : uint = 1024 * 1024 ;
37
37
38
38
// This is the starting point of rust os threads. The first thing we do
39
39
// is make sure that we don't trigger __morestack (also why this has a
@@ -84,7 +84,7 @@ impl Thread<()> {
84
84
* cast:: transmute :: < & ~Option < T > , * * mut Option < T > > ( & packet)
85
85
} ;
86
86
let main: proc ( ) = proc ( ) unsafe { * packet2 = Some ( main ( ) ) ; } ;
87
- let native = unsafe { imp:: create ( ~main) } ;
87
+ let native = unsafe { imp:: create ( stack , ~main) } ;
88
88
89
89
Thread {
90
90
native : native,
@@ -100,8 +100,14 @@ impl Thread<()> {
100
100
/// systems. Note that platforms may not keep the main program alive even if
101
101
/// there are detached thread still running around.
102
102
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 ( ) ) {
103
109
unsafe {
104
- let handle = imp:: create ( ~main) ;
110
+ let handle = imp:: create ( stack , ~main) ;
105
111
imp:: detach ( handle) ;
106
112
}
107
113
}
@@ -145,13 +151,15 @@ mod imp {
145
151
use libc:: types:: os:: arch:: extra:: { LPSECURITY_ATTRIBUTES , SIZE_T , BOOL ,
146
152
LPVOID , DWORD , LPDWORD , HANDLE } ;
147
153
use ptr;
154
+ use libc;
155
+ use cast;
148
156
149
157
pub type rust_thread = HANDLE ;
150
158
pub type rust_thread_return = DWORD ;
151
159
152
- pub unsafe fn create ( p : ~proc ( ) ) -> rust_thread {
160
+ pub unsafe fn create ( stack : uint , p : ~proc ( ) ) -> rust_thread {
153
161
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,
155
163
arg, 0 , ptr:: mut_null ( ) )
156
164
}
157
165
@@ -189,17 +197,17 @@ mod imp {
189
197
use libc:: consts:: os:: posix01:: PTHREAD_CREATE_JOINABLE ;
190
198
use libc;
191
199
use ptr;
192
- use super :: DEFAULT_STACK_SIZE ;
193
200
use unstable:: intrinsics;
194
201
195
202
pub type rust_thread = libc:: pthread_t ;
196
203
pub type rust_thread_return = * libc:: c_void ;
197
204
198
- pub unsafe fn create ( p : ~proc ( ) ) -> rust_thread {
205
+ pub unsafe fn create ( stack : uint , p : ~proc ( ) ) -> rust_thread {
199
206
let mut native: libc:: pthread_t = intrinsics:: uninit ( ) ;
200
207
let mut attr: libc:: pthread_attr_t = intrinsics:: uninit ( ) ;
201
208
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 ) ;
203
211
assert_eq ! ( pthread_attr_setdetachstate( & mut attr,
204
212
PTHREAD_CREATE_JOINABLE ) , 0 ) ;
205
213
0 commit comments