How to create intermittent sleep on Windows using C?

I want the current thread to sleep for a given time. However, another thread should be able to interrupt it and wake it earlier. On unix, it's quite simple using sleep+ pthread_kill. There are SleepExand in the windows SleepConditionVariableCS. SleepEx doesn't seem to actually make the thread sleep, since it is still handling events, so sleeping on a condition variable would be a better solution? In addition, it is somewhat unclear to me how to wake the thread, sleep with SleepEx. What is the correct solution to this problem, SleepExor SleepConditionVariableCS? (You could also indicate how to wake a thread sleeping from SleepEx? The MSDN documentation is very confusing.

+5
source share
1 answer

Create a manual reset event and wait for it using WaitForSingleObject- has a timeout parameter. See MSDN for more information.

+12
source

All Articles