Timer waking process

I want to set a timer from a process and then block the process until the timer expires or a certain interrupt is received.

Any ideas on what is the best way to do this??


QNX has a very rich mechanism for doing this. How best to do it depends on your architecture. Generally, creating a pulse event is the mechanism I favor.

This requires you to initialize a sigevent struct for a pulse, and then create the timer with this sigevent struct.

The beauty of the QNX architecture, is that you can do exactly the same thing for the interrupt. Simply populate another sigevent structure for pulse (different pulse code, so you can differentiate it from the timer expiry), and attach it to an interrupt via the attach event API.

Then you simply program the timer and recieve block. When the timer expires you’ll receive a pulse with the pulse code you chose for the timer, and when the interrupt fires, you’ll get a pulse with the pulse code you chose for the interrupt. Simple and elegant.

The functions you are interested in:


Also, the following macro will most likely prove useful:

SIGEV_PULSE_INIT( event, coid, priority, code, value ).

The QNX docs should fill in all the details…

I give you another idea.

If you want to receive not only pulses from timer, also messages
from other threads or processes, you can create a sigevent to receive pulses and wait for them in your program with MsgReceive.
If rcvid equals 0, you have received a pulse. If not, you have received
a message from another thread or process.


if (rcvid==0) // You get a pulse
// Do what you want with the timer
// You receive a message!

I have now used rcvid=MsgReceive(…); to wait for a pulse/message.

This works for my timer and Interrupt but i am having a problem.

I decided to test my code using the Keyboard interrupt.
I am using interruptAttachEvent() to attach a pulse event to the interrupt.
I have my program start, sleep for 5s econds, then attach timer and interrupt events, this ensures enter used to start program is not seen as keyboard interrupt by my program.

When I run the program I wait for the initial sleep to be over. Then I press a key.
I receive my message that the interrupt has been received and the program exits, as expected.
A command prompt is shown and the key which I pressed, eg letter, is displayed.
Then the screen freezes, ie keyboard and mouse don’t work, but I can still telnet into the machine.

Any ideas??, I have tried deataching the event from the interrupt, using InterruptDetach(), before exiting my program but this doesn’t seem to work.


I am sorry. I have never used InterruptAttach.

I have read you must use ThreadCtl( _NTO_TCTL_IO, 0 ) before using
To use it, you must be root.

To try if your timer works ok, use ClockCyles(), you can know the time
between the pulses you receive.

You can test if you receive messages writing an easy client who ask
your program (just an idea). It can be just a thread in the same process
of your program, so you dont need to know the pid and so on to use

I hope it helps ( I am amateur in QNX, ;))