Skip to content

Commit ee622cc

Browse files
committed
unix/mpthreadport: Adjust minimum thread stack, and stack limit check.
The minimum thread stack size is set by pthreads (16k bytes) so we must use that value for our minimum. The stack limit check is also adjusted to work correctly for 32-bit builds.
1 parent 26d5e91 commit ee622cc

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

unix/mpthreadport.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,14 @@ void mp_thread_start(void) {
134134
}
135135

136136
void mp_thread_create(void *(*entry)(void*), void *arg, size_t *stack_size) {
137-
// default stack size is 8k machine-words, minimum is 2k
137+
// default stack size is 8k machine-words
138138
if (*stack_size == 0) {
139139
*stack_size = 8192 * BYTES_PER_WORD;
140-
} else if (*stack_size < 2048 * BYTES_PER_WORD) {
141-
*stack_size = 2048 * BYTES_PER_WORD;
140+
}
141+
142+
// minimum stack size is set by pthreads
143+
if (*stack_size < PTHREAD_STACK_MIN) {
144+
*stack_size = PTHREAD_STACK_MIN;
142145
}
143146

144147
// set thread attributes
@@ -163,7 +166,8 @@ void mp_thread_create(void *(*entry)(void*), void *arg, size_t *stack_size) {
163166
}
164167

165168
// adjust stack_size to provide room to recover from hitting the limit
166-
*stack_size -= 1024 * BYTES_PER_WORD;
169+
// this value seems to be about right for both 32-bit and 64-bit builds
170+
*stack_size -= 8192;
167171

168172
// add thread to linked list of all threads
169173
thread_t *th = malloc(sizeof(thread_t));

0 commit comments

Comments
 (0)