aboutsummaryrefslogtreecommitdiffstats
path: root/fastos
diff options
context:
space:
mode:
Diffstat (limited to 'fastos')
-rw-r--r--fastos/src/vespa/fastos/unix_thread.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/fastos/src/vespa/fastos/unix_thread.cpp b/fastos/src/vespa/fastos/unix_thread.cpp
index 3fcba5e61b1..2ba6e306e40 100644
--- a/fastos/src/vespa/fastos/unix_thread.cpp
+++ b/fastos/src/vespa/fastos/unix_thread.cpp
@@ -4,6 +4,10 @@
#include <thread>
#include <unistd.h>
+#ifdef __linux__
+extern "C" { size_t __pthread_get_minstack(const pthread_attr_t *); }
+#endif
+
namespace {
#ifdef __linux__
std::atomic_size_t _G_nextCpuId(0);
@@ -40,8 +44,6 @@ bool FastOS_UNIX_Thread::Initialize (int stackSize, int stackGuardSize)
pthread_attr_init(&attr);
pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
-
- pthread_attr_setstacksize(&attr, stackSize);
#ifdef __linux__
if (_G_maxNumCpus > 0) {
int cpuid = _G_nextCpuId.fetch_add(1)%_G_maxNumCpus;
@@ -61,6 +63,13 @@ bool FastOS_UNIX_Thread::Initialize (int stackSize, int stackGuardSize)
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
+ size_t adjusted_stack_size = stackSize;
+#ifdef __linux__
+ ssize_t stack_needed_by_system = __pthread_get_minstack(&attr);
+ adjusted_stack_size += stack_needed_by_system;
+#endif
+ pthread_attr_setstacksize(&attr, adjusted_stack_size);
+
rc = (0 == pthread_create(&_handle, &attr, FastOS_ThreadHook, this));
if (rc)
_handleValid = true;