From 0cb2617fa541dbcf53188b492a34f96ad0cf4ef8 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Mon, 2 Jun 2008 04:34:09 +0000 Subject: [PATCH] Before starting to wait the undertaker does now check whether there's already a dead thread available. Fixes a race condition. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25754 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/kernel/thread.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/system/kernel/thread.cpp b/src/system/kernel/thread.cpp index 1035dd3a1e..4e1cb2195e 100644 --- a/src/system/kernel/thread.cpp +++ b/src/system/kernel/thread.cpp @@ -540,21 +540,21 @@ undertaker(void* /*args*/) { while (true) { // wait for a thread to bury - ConditionVariableEntry conditionEntry; - InterruptsSpinLocker locker(thread_spinlock); - sUndertakerCondition.Add(&conditionEntry); - locker.Unlock(); - conditionEntry.Wait(); + while (sUndertakerEntries.IsEmpty()) { + ConditionVariableEntry conditionEntry; + sUndertakerCondition.Add(&conditionEntry); + locker.Unlock(); + + conditionEntry.Wait(); + + locker.Lock(); + } - locker.Lock(); UndertakerEntry* _entry = sUndertakerEntries.RemoveHead(); locker.Unlock(); - if (_entry == NULL) - continue; - UndertakerEntry entry = *_entry; // we need a copy, since the original entry is on the thread's stack