Best way to make a periodic thread

I’m coming from RTlinux world where exist a function to make a periodic task.
Now in QNX I need a periodic thread but I don’t know if a specific function like in Rtlinux exist so I’m trying it setting a timer that throw a signal every Xusec and the “periodic thread” consist in a:
code to make periodically
My question is if this is a good method to make a periodic task. If it isn’t, do you know a better way?
If it’s OK,which is fastest to notify from timer, a pulse or a event like SIGALRM?

Thanks a lot; AlbeRT

That makes sense yes.

Signals are the fastest (that was true with 6.1, that may have changed with more rencent version of OS). However signal are kinda messy do deal with (mainly when thread are involved) instead look at using a pulse. With signal if the process inside the loop takes longer then the timer is set to, the signal will be send and the code interrupted (like a CTRL-C). That can be dealth with by masking signals, but that’s what I’m talking about when I said messy ;-)

With a pulse it would look like:

Create channel ChannelCreate()
create timer and pulse; timer_create()
Set timer to periodicly send a pulse at given interval; timer_set()

for(;:wink: { // this is better then while(1) as some compiler or source checking program will complain about while(1) always evaluating to true
wait pulse; MsgReceivePulse ()
do what you need to; foo()

The advantage is that MsgRecivePulse could be waken up by many type of pulse. One comming from the timer and one comming from the keyboard for example to process key event. If you’d use MsgReceive() you could even receive messages as well as Pulses