Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - One more question on timer_create: (5 Items)
   
One more question on timer_create  
Hello!

In comments, to TimerCreate() there is the following text.

If you use signals for event notification, note that signals are always delivered to the process and not directly to the
 thread that created or armed the timer. You can change this by using a sigev_notify of SIGEV_SIGNAL_THREAD.

Does this mean that in case of SIGEV_SIGNAL_THREAD signal will be delivered to a thread that armed the timer (i.e. 
called timer_settime())?
If the answer is "yes" that's very bad for me and that limits the usability of feature. I would prefer to be able to 
schedule the timer from any threads while receiving signals in a thread that created the timer.
Re: One more question on timer_create  
As per the docs..

SIGEV_SIGNAL_THREAD

Send a signal to a specific thread, depending on the situation:

     * If used with MsgSend*(), MsgReceive*(), and MsgDeliverEvent(), the thread is the one identified by the rcvid that
 MsgReceive*() returns.
     * For timers, it's the thread that called timer_settime().
     * For InterruptAttach() and InterruptAttachEvent(), it's the thread attaching to the interrupt.
     * For asyncmsg_channel_create(), it's a random thread in the process.
     * For SyncMutexEvent(), it's the thread that called the function.

In the case of timers, SyncMutexEvent(), and interrupts, if the thread dies before the event gets delivered, the kernel 
sends the signal to a random thread in the same process.

The following fields are used:

int sigev_signo
     The signal to raise. This must be in the range from 1 through NSIG - 1.
short sigev_code
     A code to be interpreted by the signal handler. This must be in the range from SI_MINAVAIL through SI_MAXAVAIL.
void *sigev_value.sival_int
     A 32-bit value to be interpreted by the signal handler.

The initialization macro is:

SIGEV_SIGNAL_THREAD_INIT( &event, signal, value, code )

Oleh Derevenko wrote:
> Hello!
> 
> In comments, to TimerCreate() there is the following text.
> 
> If you use signals for event notification, note that signals are always delivered to the process and not directly to 
the thread that created or armed the timer. You can change this by using a sigev_notify of SIGEV_SIGNAL_THREAD.
> 
> Does this mean that in case of SIGEV_SIGNAL_THREAD signal will be delivered to a thread that armed the timer (i.e. 
called timer_settime())?
> If the answer is "yes" that's very bad for me and that limits the usability of feature. I would prefer to be able to 
schedule the timer from any threads while receiving signals in a thread that created the timer.

I think you will have to use SIGEV_SIGNAL and mask the signal from all threads but your timer notification thread then.

> _______________________________________________
> OSTech
> http://community.qnx.com/sf/go/post26783
> 

-- 
cburgess@qnx.com
Re: One more question on timer_create  
That's sad. :(
But let it be. I'll overcome it.

> As per the docs..
> 
> SIGEV_SIGNAL_THREAD
> 
>      * For timers, it's the thread that called timer_settime().
Re: One more question on timer_create  
One more clarification please...
If I have several timers that send the same signal to the same thread via SIGEV_SIGNAL_THREAD, can I have one signal 
queued for every timer or is that just a single signal for all the timers?
Re: One more question on timer_create  
On Mon, Apr 13, 2009 at 01:49:34PM -0400, Oleh Derevenko wrote:
> If I have several timers that send the same signal to the same thread via SIGEV_SIGNAL_THREAD, can I have one signal 
queued for every timer or is that just a single signal for all the timers?

It depends on the signal code value (sigev_code in the sigevent). If they're
the same, there'll be one signal from all the timers. If the codes are 
different, you'll get a signal from each.

-- 
Brian Stecher (bstecher@qnx.com)        QNX Software Systems
phone: +1 (613) 591-0931 (voice)        175 Terence Matthews Cr.
       +1 (613) 591-3579 (fax)          Kanata, Ontario, Canada K2M 1W8