Reputation: 14251
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.
Upvotes: 6
Views: 2308
Reputation: 24857
Create a manual reset event and wait on it with WaitForSingleObject
- has a timeout parameter. See MSDN for details.
Upvotes: 13