Skip to content

Commit

Permalink
fix defect in semaphore implementation which caused application hang …
Browse files Browse the repository at this point in the history
…at exit time, because not all worker threads get woken up when task semaphore is repeatedly posted (to wake them up) after setting the stopping flag in the thread pool
  • Loading branch information
richard42 authored and nickrasmussen committed Aug 8, 2018
1 parent 9e3913c commit 4706d61
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion IlmBase/IlmThread/IlmThreadSemaphorePosixCompat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,16 @@ Semaphore::post ()

if (_semaphore.numWaiting > 0)
{
if (int error = ::pthread_cond_signal (&_semaphore.nonZero))
int error;
if (_semaphore.numWaiting > 1 && _semaphore.count > 1)
{
error = ::pthread_cond_broadcast (&_semaphore.nonZero);
}
else
{
error = ::pthread_cond_signal (&_semaphore.nonZero);
}
if (error)
{
::pthread_mutex_unlock (&_semaphore.mutex);

Expand Down

0 comments on commit 4706d61

Please sign in to comment.