Hi,
What about a Thread::sleepOrExit(const int sleepTimeMillisecond) method, that does sleep for the given time, while still checking threadShouldExit regularly and exiting then ?
The code is very simple:
/** Sleep this thread for the given duration in millisecond.
Contrary to Thread::sleep, if the thread is signaled to exit, this method exit immediately instead of after the duration time elapsed. */
bool sleepOrExit(const unsigned int durationMs) const
{
double endTime = Time::getMillisecondCounter() + durationMs;
while (!threadShouldExit() && Time::getMillisecondCounter() < endTime) sleep(roundDoubleToInt(jlimit(0, 30.0, endTime - Time::getMillisecondCounter())));
}