I need to call a function asynchronously for every x miliseconds. I am coding in C++, Linux environment. What functions could I call to achieve that?
The timer object supports properties that let you specify the MATLAB® commands that execute when a timer fires, and for other timer object events, such as starting, stopping, or when an error occurs. These are called callbacks.
A callback is any executable code that is passed as an argument to other code, which is expected to call back (execute) the argument at a given time [Source : Wiki]. In simple language, If a reference of a function is passed to another function as an argument to call it, then it will be called as a Callback function.
To process the timer's expiry in your application, you should also define a callback function. This code raises a SIGALRM signal after 1 second. If you want to increase the timer delay to five seconds, just call alarm(5) instead. To stop the timer, pass a value of 0: alarm(0).
Look into the Boost timers.
http://www.boost.org/doc/libs/1_40_0/doc/html/boost_asio/tutorial/tuttimer2.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With