SIGEV_SIGNAL_THREAD question

I have created a timer and want to deliver a signal to a specific
thread using the ‘SIGEV_SIGNAL_THREAD’ specification in
the ‘sigevent’ structure. How is the thread determined? There
doesnt seem to be a way to specify it.


Art Hays
National Institutes of Health
avhays@nih.gov

I think the only way to do that is to block the signal for all the threads
(easier to do before threads are created) and then wait for it explicitly in
one thread (sigwaitinfo). You probably also want to set SA_SIGINFO to queue
them.

– igor

“Art Hays” <avhays@nih.gov> wrote in message
news:b87n3n$kcg$1@inn.qnx.com

I have created a timer and want to deliver a signal to a specific
thread using the ‘SIGEV_SIGNAL_THREAD’ specification in
the ‘sigevent’ structure. How is the thread determined? There
doesnt seem to be a way to specify it.


Art Hays
National Institutes of Health
avhays@nih.gov

Art Hays <avhays@nih.gov> wrote:

I have created a timer and want to deliver a signal to a specific
thread using the ‘SIGEV_SIGNAL_THREAD’ specification in
the ‘sigevent’ structure. How is the thread determined? There
doesnt seem to be a way to specify it.

They’re always delivered to thread 1 for timer events. Igor’s suggestion
is the way to go.


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

I would appreciate a little more insight-

Assume I have a process that creates one thread. In that thread I create a timer that
sends a signal. What happens if:

1.) I set SIGEV_SIGNAL?

2.) I set SIGEV_SIGNAL_THREAD?


<bstecher@qnx.com> wrote in message news:b88qtq$sq1$1@nntp.qnx.com

Art Hays <> avhays@nih.gov> > wrote:
I have created a timer and want to deliver a signal to a specific
thread using the ‘SIGEV_SIGNAL_THREAD’ specification in
the ‘sigevent’ structure. How is the thread determined? There
doesnt seem to be a way to specify it.

They’re always delivered to thread 1 for timer events. Igor’s suggestion
is the way to go.


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

Art Hays <avhays@nih.gov> wrote:

Assume I have a process that creates one thread. In that thread I create a timer that
sends a signal. What happens if:

1.) I set SIGEV_SIGNAL?

The signal is delivered to a thread, which one being chosen by the
POSIX rules about deciding which thread a signal goes to in a multi-threaded
program (which are rather long and obtuse, so I won’t list them here).

2.) I set SIGEV_SIGNAL_THREAD?

The signal is delivered to thread 1.


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

<bstecher@qnx.com> wrote in message news:b89fpj$dhr$1@nntp.qnx.com

Art Hays <> avhays@nih.gov> > wrote:
Assume I have a process that creates one thread. In that thread I create a timer that
sends a signal. What happens if:

1.) I set SIGEV_SIGNAL?

The signal is delivered to a thread, which one being chosen by the
POSIX rules about deciding which thread a signal goes to in a multi-threaded
program (which are rather long and obtuse, so I won’t list them here).

2.) I set SIGEV_SIGNAL_THREAD?

The signal is delivered to thread 1.

I’m not sure what’s going on. In my process I create one thread (it has tid 2). I also
create the timer in this thread, and do the sigaction() call from this thread. The timer causes a
signal to be delivered every msec. This is what I find:

1.) If I set SIGEV_SIGNAL then tid 2 receives the signal. There are
times when the signal handler takes longer than a msec. Sometimes I find
the signal handler is reentered by the next signal from the timer, which shouldnt
occur.

2.) If I set SIGEV_SIGNAL_THREAD then tid 2 still receives the signal. However,
the signal handler is never reentered even when it takes longer than a msec.



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

Art Hays <avhays@nih.gov> wrote:

1.) If I set SIGEV_SIGNAL then tid 2 receives the signal. There are
times when the signal handler takes longer than a msec. Sometimes I find
the signal handler is reentered by the next signal from the timer, which shouldnt
occur.

I believe the second invocation will be running on thread 1. When the
signal gets ‘masked’ by the handler invocation, it gets masked at the
thread level, so the second signal gets delivered to the other thread.
Whether the ‘mask’ should be occurring at the thread or process level
is something I’m still digging through the POSIX standard to try to
determine.


2.) If I set SIGEV_SIGNAL_THREAD then tid 2 still receives the signal. However,
the signal handler is never reentered even when it takes longer than a msec.

Sorry, I missed a line when I was looking at the code originally. For
timers, SIGEV_SIGNAL_THREAD’s will be delivered to the thread that did
the timer_settime() call.

\

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

<bstecher@qnx.com> wrote in message news:b8bnvt$rbo$1@nntp.qnx.com

Art Hays <> avhays@nih.gov> > wrote:
1.) If I set SIGEV_SIGNAL then tid 2 receives the signal. There are
times when the signal handler takes longer than a msec. Sometimes I find
the signal handler is reentered by the next signal from the timer, which shouldnt
occur.

I believe the second invocation will be running on thread 1. When the
signal gets ‘masked’ by the handler invocation, it gets masked at the
thread level, so the second signal gets delivered to the other thread.
Whether the ‘mask’ should be occurring at the thread or process level
is something I’m still digging through the POSIX standard to try to
determine.

It only seems to happen in conjuction with a kernel call from thread 2, but
I havent tracked down what call.

2.) If I set SIGEV_SIGNAL_THREAD then tid 2 still receives the signal. However,
the signal handler is never reentered even when it takes longer than a msec.

Sorry, I missed a line when I was looking at the code originally. For
timers, SIGEV_SIGNAL_THREAD’s will be delivered to the thread that did
the timer_settime() call.

This is the behavior I would want- it gives me a way to specify the thread that gets
the signal.


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