Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 :)

like image 480
waas1919 Avatar asked Mar 31 '26 04:03

waas1919


1 Answers

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.

like image 104
graywolf Avatar answered Apr 02 '26 19:04

graywolf