From 97bbc8f965ec50fc7509881a5b63f2a14d0c9666 Mon Sep 17 00:00:00 2001 From: Christian Prochaska Date: Wed, 28 Oct 2015 16:14:13 +0100 Subject: [PATCH] pthread: don't destroy the pthread object for the main thread The pthread object for the main thread initializes its 'Thread_base' base class part with a reference to the 'Thread_base' object of the Genode main thread. Therefore the pthread object for the main thread should never be destroyed, as this would also destroy the Genode 'Thread_base' object. Fixes #1760 --- repos/libports/src/lib/pthread/thread.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/repos/libports/src/lib/pthread/thread.cc b/repos/libports/src/lib/pthread/thread.cc index adbaae190..4b0cde8cc 100644 --- a/repos/libports/src/lib/pthread/thread.cc +++ b/repos/libports/src/lib/pthread/thread.cc @@ -129,9 +129,16 @@ extern "C" { if (is_main && !strcmp(name, "main")) { /* create a pthread object containing copy of main Thread_base */ static struct pthread_attr main_thread_attr; - static struct pthread main(*myself, &main_thread_attr); + static struct pthread *main = nullptr; + if (!main) { + /* + * The pthread object does not get deleted, because this would + * also delete the 'Thread_base' of the main thread. + */ + main = new (Genode::env()->heap()) struct pthread(*myself, &main_thread_attr); + } - return &main; + return main; } PERR("pthread_self() called from alien thread named '%s'", name);