summaryrefslogtreecommitdiffstatshomepage
path: root/unix/mpthreadport.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-07-11 14:59:47 +0000
committerDamien George <damien.p.george@gmail.com>2016-07-11 14:59:47 +0000
commitee622cc1edd624302c526ea00f08fe0ab962d86c (patch)
treebb57b539addf056a7408ee3e0a6ca92770f42cbd /unix/mpthreadport.c
parent26d5e91bf39463ca72f0a5f5d2c79b8be1d29541 (diff)
downloadmicropython-ee622cc1edd624302c526ea00f08fe0ab962d86c.tar.gz
micropython-ee622cc1edd624302c526ea00f08fe0ab962d86c.zip
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.
Diffstat (limited to 'unix/mpthreadport.c')
-rw-r--r--unix/mpthreadport.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/unix/mpthreadport.c b/unix/mpthreadport.c
index e5cfe7a669..663d3a5dee 100644
--- a/unix/mpthreadport.c
+++ b/unix/mpthreadport.c
@@ -134,11 +134,14 @@ void mp_thread_start(void) {
}
void mp_thread_create(void *(*entry)(void*), void *arg, size_t *stack_size) {
- // default stack size is 8k machine-words, minimum is 2k
+ // default stack size is 8k machine-words
if (*stack_size == 0) {
*stack_size = 8192 * BYTES_PER_WORD;
- } else if (*stack_size < 2048 * BYTES_PER_WORD) {
- *stack_size = 2048 * BYTES_PER_WORD;
+ }
+
+ // minimum stack size is set by pthreads
+ if (*stack_size < PTHREAD_STACK_MIN) {
+ *stack_size = PTHREAD_STACK_MIN;
}
// set thread attributes
@@ -163,7 +166,8 @@ 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
- *stack_size -= 1024 * BYTES_PER_WORD;
+ // this value seems to be about right for both 32-bit and 64-bit builds
+ *stack_size -= 8192;
// add thread to linked list of all threads
thread_t *th = malloc(sizeof(thread_t));