I want the current thread to sleep for a given time. However, another thread should be able to interrupt it and wake it up early. In unix this is fairly simple using sleep
+ pthread_kill
. In windows there is SleepEx
and SleepConditionVariableCS
. SleepEx doesnt seem to actually cause the thread to sleep since it is still processing events, so would sleeping on a condition variable be a better solution? Furthermore, it is somewhat unclear to me how to wake a thread sleeping with SleepEx. What is correct solution to this problem, SleepEx
or SleepConditionVariableCS
? (Also, could you point out how to wake a thread sleeping with SleepEx
? The MSDN documentation is very confusing.
Create a manual reset event and wait on it with WaitForSingleObject
- has a timeout parameter. See MSDN for details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With