C ++ 11 a way to create a timer that can be "stopped" if necessary

I need to call a function every X seconds to show the progress of a long-running function, but I want to refuse a notification if the function ends before the next tick to update the execution. I just recently started using C ++ 11, and I don't know if there is a way to achieve this using the correct C ++ 11 syntax / objects.

Basically, I'm trying to figure out if there is a way to access the same functions as posix timer_create and timer_delete functions using C ++ 11 streams and asynchronous functions.

I found this question. How to create timer events using C ++ 11? , which covers almost everything I need, but I could not figure out if there is a way to stop the asynchronous call after it is "sent".

Is this possible now in C ++ 11?

+4
source share
1 answer

Introduction

A simple solution is to make the timer set to execute f in N units of time potentially sleep for N units of time, but if something interrupts sleep, we should not complete task f.

std:: condition_variable , - wait_for. false, , true, .

+4

Source: https://habr.com/ru/post/1544218/


All Articles