Reputation: 1067
I need to make a thread waiting until either
After some research I've found out pthreads got pthread_cond_timedwait which could be useful in this case if I'd be using pthreads.
I'm using C++ 11 threads instead. Is there a suitable alternative for me without completely passing to pthreads?
Upvotes: 7
Views: 1808
Reputation: 477040
Yes, you want std::condition_variable
from <condition_variable>
, which has a member function wait_for
that takes a time duration.
The condition_variable class is a synchronization primitive that can be used to block a thread, or multiple threads at the same time, until:
- a notification is received from another thread
- a timeout expires
Upvotes: 11