From 0b3dfa087bbe192aa43f3d3d84f214c1fdb0d814 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 9 Jan 2018 11:52:17 +0000 Subject: [PATCH] thread_pthread.c: round stack size * thread_pthread.c (rb_thread_create_timer_thread): round up additional stack size to PTHREAD_STACK_MIN, to get rid of EINVAL at pthread_attr_setstacksize(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61722 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- thread_pthread.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/thread_pthread.c b/thread_pthread.c index 3f4310dbfb..0313ac8b00 100644 --- a/thread_pthread.c +++ b/thread_pthread.c @@ -1596,6 +1596,7 @@ rb_thread_create_timer_thread(void) } # ifdef PTHREAD_STACK_MIN { + size_t stack_min = PTHREAD_STACK_MIN; /* may be dynamic, get only once */ const size_t min_size = (4096 * 4); /* Allocate the machine stack for the timer thread * at least 16KB (4 pages). FreeBSD 8.2 AMD64 causes @@ -1609,9 +1610,11 @@ rb_thread_create_timer_thread(void) THREAD_DEBUG != 0 #endif }; - stack_size = PTHREAD_STACK_MIN; /* may be dynamic, get only once */ + stack_size = stack_min; if (stack_size < min_size) stack_size = min_size; - if (needs_more_stack) stack_size += BUFSIZ; + if (needs_more_stack) { + stack_size += +((BUFSIZ - 1) / stack_min + 1) * stack_min; + } err = pthread_attr_setstacksize(&attr, stack_size); if (err != 0) { rb_bug("pthread_attr_setstacksize(.., %"PRIuSIZE") failed: %s",