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) { while (true) {
// wait for a thread to bury // wait for a thread to bury
ConditionVariableEntry conditionEntry;
InterruptsSpinLocker locker(thread_spinlock); InterruptsSpinLocker locker(thread_spinlock);
while (sUndertakerEntries.IsEmpty()) {
ConditionVariableEntry conditionEntry;
sUndertakerCondition.Add(&conditionEntry); sUndertakerCondition.Add(&conditionEntry);
locker.Unlock(); locker.Unlock();
conditionEntry.Wait(); conditionEntry.Wait();
locker.Lock(); locker.Lock();
}
UndertakerEntry* _entry = sUndertakerEntries.RemoveHead(); UndertakerEntry* _entry = sUndertakerEntries.RemoveHead();
locker.Unlock(); locker.Unlock();
if (_entry == NULL)
continue;
UndertakerEntry entry = *_entry; UndertakerEntry entry = *_entry;
// we need a copy, since the original entry is on the thread's stack // we need a copy, since the original entry is on the thread's stack