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
This commit is contained in:
Ingo Weinhold 2008-06-02 04:34:09 +00:00
parent e72e5275ff
commit 0cb2617fa5
1 changed files with 9 additions and 9 deletions

View File

@ -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