Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Timer Callback in C++

Tags:

c++

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?

like image 382
Steveng Avatar asked Dec 06 '10 05:12

Steveng


People also ask

What is a timer callback function?

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.

What is callback function in C?

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.

How to use timer in Linux?

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


1 Answers

Look into the Boost timers.

http://www.boost.org/doc/libs/1_40_0/doc/html/boost_asio/tutorial/tuttimer2.html

like image 190
neckbeard Avatar answered Nov 15 '22 11:11

neckbeard