Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you create asynchronous timers in OS X C code?

So this question is really "Why are time.h not the same on OS X and Linux?" but, I've made my peace with those differences.

To create timers on a 'Unix' system, I followed this tutorial http://www.helsinki.fi/atk/unix/dec_manuals/DOC_40D/APS33DTE/DOCU_007.HTM#timer-type-sec

which requires the use of <sys/time.h> and calling timer_create(), then setting up a signal handler for the signal type. This I know how to do. The question is, how is the same thing achieved on OS X?

The key thing to note is that these timers need to be realtime, that is, asynchronously queued and must use the sa_sigaction field of a struct sigaction, so that metadata associated with the timer alarm can be passed to the signal handler. This is described in more detail here http://www.helsinki.fi/atk/unix/dec_manuals/DOC_40D/APS33DTE/DOCU_006.HTM#sigevent-sec.

like image 353
emish Avatar asked Nov 14 '22 06:11

emish


1 Answers

Have you looked into setitimer()?

like image 129
Ken Thomases Avatar answered Dec 06 '22 11:12

Ken Thomases