aboutsummaryrefslogtreecommitdiffstats
path: root/fastos
diff options
context:
space:
mode:
authorArne Juul <arnej@verizonmedia.com>2021-02-24 12:13:53 +0000
committerArne Juul <arnej@verizonmedia.com>2021-02-24 12:13:53 +0000
commit780bb0846b7b1ad532742340c938aa9372ad0a18 (patch)
tree81ad7c2e12b311074e3be5151ac08bb523dd7e3b /fastos
parent3e0954075fde4f01717c9a9e987231af95812a31 (diff)
adjust stack size by adding system minimum size
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;