waas1919
waas1919

Reputation: 2605

C++11 std::this_thread - How to cancel sleep_until ()?

Is there any way to "cancel" the:

std::this_thread::sleep_until(now + std::chrono::milliseconds(200));

Let's imagine the following scenario:

I set my thread to wake up in 200ms... but after 10ms, I receive a new request that my thread must wake up in 100ms...

So the thread should wake up in: 100ms and then at 200ms (after the current time, of course).

Thanks :)

Upvotes: 3

Views: 2899

Answers (1)

graywolf
graywolf

Reputation: 7490

I don't think you can do this with sleep_until. Have a look at condition variables ( http://www.cplusplus.com/reference/condition_variable/condition_variable/ ). Should be usable for exactly what you want.

Upvotes: 9

Related Questions