From b092f872b3bba4a3a04577ce895827c4b1e2863b Mon Sep 17 00:00:00 2001 From: Hamish Morrison Date: Thu, 4 Jun 2015 13:21:17 +0100 Subject: [PATCH] fork: update the thread id in the pthread struct after forking Otherwise the child process's main thread will inherit the thread id of its parent and pthread operations will be directed at the wrong thread. --- src/system/libroot/posix/unistd/fork.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/system/libroot/posix/unistd/fork.c b/src/system/libroot/posix/unistd/fork.c index a771e9ed2a..8d8a963795 100644 --- a/src/system/libroot/posix/unistd/fork.c +++ b/src/system/libroot/posix/unistd/fork.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -147,6 +148,8 @@ fork(void) // we are the child // ToDo: initialize child __main_thread_id = find_thread(NULL); + pthread_self()->id = __main_thread_id; + mutex_init(&sForkLock, FORK_LOCK_NAME); // TODO: The lock is already initialized and we in the fork()ing // process we should make sure that it is in a consistent state when