wait with a condition variable instead of a this_thread::sleep_for so that waiting can be cancelled when we stop/shutdown the data thread (see #151)

This commit is contained in:
Benjamin Sergeant
2020-01-28 10:04:32 -08:00
parent 1c7ccbae12
commit 422c7ff855
2 changed files with 8 additions and 2 deletions

View File

@ -169,6 +169,7 @@ namespace ix
// wait until working thread will exit
// it will exit after close operation is finished
_stop = true;
_sleepCondition.notify_one();
_thread.join();
_stop = false;
}
@ -282,8 +283,8 @@ namespace ix
// Only sleep if we are retrying
if (duration.count() > 0)
{
// to do: make sleeping conditional
std::this_thread::sleep_for(duration);
std::unique_lock<std::mutex> lock(_sleepMutex);
_sleepCondition.wait_for(lock, duration);
}
// Try to connect synchronously