aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ports/unix/mpthreadport.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/ports/unix/mpthreadport.c b/ports/unix/mpthreadport.c
index c604c5d21..9c696f47f 100644
--- a/ports/unix/mpthreadport.c
+++ b/ports/unix/mpthreadport.c
@@ -221,7 +221,11 @@ void mp_thread_create(void *(*entry)(void *), void *arg, size_t *stack_size) {
// adjust stack_size to provide room to recover from hitting the limit
// this value seems to be about right for both 32-bit and 64-bit builds
- *stack_size -= 8192;
+ if (*stack_size >= 2 * 8192) {
+ *stack_size -= 8192;
+ } else {
+ *stack_size /= 2;
+ }
// add thread to linked list of all threads
thread_t *th = malloc(sizeof(thread_t));