1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-07-12 03:59:15 +00:00

Fix race while exiting

Fix again TimerThread::idle_loop() to prevent a
theoretical race with 'exit' flag in ~Thread().

Indeed in Thread d'tor we raise 'exit' and then
call notify() that is lock protected, so we
have to check again for 'exit' before going to
sleep in idle_loop().

Also same change in Thread::idle_loop() where we
now check for 'exit' before to go to sleep.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2013-01-16 09:26:10 +01:00
parent 8737b26a23
commit c465f4c4df
2 changed files with 7 additions and 4 deletions

View file

@ -1588,7 +1588,7 @@ void Thread::idle_loop() {
// particular we need to avoid a deadlock in case a master thread has, // particular we need to avoid a deadlock in case a master thread has,
// in the meanwhile, allocated us and sent the wake_up() call before we // in the meanwhile, allocated us and sent the wake_up() call before we
// had the chance to grab the lock. // had the chance to grab the lock.
if (!is_searching && Threads.sleepWhileIdle) if (!is_searching && !do_exit)
sleepCondition.wait(mutex); sleepCondition.wait(mutex);
mutex.unlock(); mutex.unlock();

View file

@ -76,10 +76,13 @@ void TimerThread::idle_loop() {
while (!do_exit) while (!do_exit)
{ {
mutex.lock(); mutex.lock();
do sleepCondition.wait_for(mutex, msec ? msec : INT_MAX);
while (!msec && !do_exit); // Don't allow wakeups when msec = 0 if (!do_exit)
sleepCondition.wait_for(mutex, msec ? msec : INT_MAX);
mutex.unlock(); mutex.unlock();
if (msec)
check_time(); check_time();
} }
} }