Improvement to ThreadWait

This commit is contained in:
Ali Mashtizadeh 2015-01-18 13:56:15 -08:00
parent 29dd4d3af8
commit 4f15c9fd01

View File

@ -347,10 +347,26 @@ Syscall_ThreadSleep(uint64_t time)
uint64_t
Syscall_ThreadWait(uint64_t tid)
{
int status;
Thread *cur = Thread_Current();
Semaphore_Acquire(&cur->proc->zombieSemaphore);
return Thread_Wait(cur, tid);
/*
* Acquire the zombie semaphore see if the specified thread has exited or
* any thread if tid == 0. If the specified thread hasn't exited wait
* again on the semaphore. POSIX does not give any guarentees if multiple
* threads wait on the same thread and neither do we.
*
* As a precaution we call Thread_Scheduler to prevent looping on the
* semaphore acquire-release.
*/
while (1) {
Semaphore_Acquire(&cur->proc->zombieSemaphore);
status = Thread_Wait(cur, tid);
if (status != 0)
return status;
Semaphore_Release(&cur->proc->zombieSemaphore);
Thread_Scheduler();
}
}
uint64_t