Project Home
Project Home
Trackers
Trackers
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - signal priorities issue: (5 Items)
   
signal priorities issue  
Realtime signals help information should be more accurate.

As stated in help topic on sigqueue() function, “Should any of multiple pending signals in the range SIGRTMIN to 
SIGRTMAX be selected for delivery, the lowest numbered one is delivered.”   This assertion complies with POSIX Realtime
 Signal Concept (http://www.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_04.html): “When multiple unblocked 
signals, all in the range SIGRTMIN to SIGRTMAX, are pending, the behavior shall be as if the implementation delivers the
 pending unblocked signal with the lowest signal number within that range. No other ordering of signal delivery is 
specified. If, when a pending signal is delivered, there are additional signals queued to that signal number, the signal
 shall remain pending. Otherwise, the pending indication shall be reset.” 
In fact, as shown in book “Цилюрик О., Горошко Е. QNX/UNIX: анатомия параллелизма. 
ISBN 5-93286-088-X” (http://www.symbol.ru/alphabet/357604.html ), QNX Neutrino behaves opposite manner (look at file s5
.cc in archive pthread.tgz http://www.books.ru/library/qnx-unix/ ): while pending RT signals are delivered to process 
using signal handler function, signals with highest numbers are received first. I attach slightly changed simple program
 s5_sighandler.c that illustrates this behavior. The same order of signal delivery demonstrates sigsuspend() function in
 conjunction with signal handler function.
On the other hand,  if queued RT signals are not “delivered” but “accepted” (xsh_chap02_04.html  terminology) by 
process with sigwaitinfo() function, QNX Neutrino behaves in accordance with IEEE Std 1003.1, 2004 Edition - signals 
with lowest numbers are delivered first. This is illustrated by s5_sigwaitinfo.c program. 

It seems to me that RT signal help documentation require some refinement:
1) Neatly distinguish signal delivery and accepting in help topics. Explain what does signal catching means every time 
this term appears in help topics.  
2) Neatly describe the order of queued RT signals delivery and accepting as it is implemented by QNX Neutrino. 
3) Neatly explain in sigwaitinfo() help topic that accepting signals must be blocked like it is written in sigwait() 
help topic.  
4) Bring help topics on concrete functions to conformity with chapter “The QNX Neutrino Microkernel”. For example, in 
this chapter I read  “The POSIX standard includes the concept of queued realtime signals. QNX Neutrino supports 
optional queuing of any signal, not just realtime signals. The queuing can be specified on a signal-by-signal basis 
within a process. Each signal can have an associated 8-bit code and a 32-bit value.. . .  As a result, signals are 
delivered in priority order with lower signal numbers having higher priority. This conforms with the POSIX standard, 
which states that existing signals have priority over the new realtime signals. . . . The OS supports the 32 standard 
POSIX signals (as in UNIX) as well as the POSIX realtime signals, both numbered from a kernel-implemented set of 64 
signals with uniform functionality. While the POSIX standard defines realtime signals as differing from UNIX-style 
signals (in that they may contain four bytes of data and a byte code and may be queued for delivery), this functionality
 can be explicitly selected or deselected on a per-signal basis, allowing this converged implementation to still comply 
with the standard. Incidentally, the UNIX-style signals can select POSIX realtime signal 
queuing, if the application wants it.”
But help topic about sigqueue() function tells me:  “Should any of multiple pending signals in the range SIGRTMIN to 
SIGRTMAX be selected for delivery, the lowest numbered one is delivered. The selection order between realtime and 
nonrealtime signals, or between multiple pending nonrealtime signals, is unspecified.”

Attachment: file signals.tar.gz, containing  s5_sighandler.c  s5_sigwaitinfo.c programs.
Attachment: Text signals.tar.gz 5.75 KB
Re: signal priorities issue  
consider thread a that has two signals pending SIGRTMIN and SIGRTMAX, but blocked.

Now unblock them.  This causes the signals to be queued for delivery, in signal number order.

As thread a exits the kernel, the signal handler for SIGRTMIN is setup to run.  But as the kernel
is in the process of making the thread ready, it then 'delivers' the second signal, SIGRTMAX
to the thread, which queues up the handler for that signal, and so on.

Thus the signal handlers 'stack', and effectively execute in reverse order.

-- 
cburgess@qnx.com
Re: signal priorities issue  
Colin Burgess, thank You for reply.

I understood Your explanation, maybe not quite perfectly. So I have some questions and objections.

1.	If signals are ‘stacked’, it seems they must be delivered in strictly reverse order, i.e. 
Sent:
signal sent: 56 with val = 0
signal sent: 56 with val = 1
signal sent: 56 with val = 2
signal sent: 55 with val = 0
signal sent: 55 with val = 1
signal sent: 55 with val = 2
signal sent: 54 with val = 0
signal sent: 54 with val = 1
signal sent: 54 with val = 2
…
Received:
received signal 56 code = -2 val = 2
received signal 56 code = -2 val = 1
received signal 56 code = -2 val = 0
received signal 55 code = -2 val = 2
received signal 55 code = -2 val = 1
received signal 55 code = -2 val = 0
received signal 54 code = -2 val = 2
received signal 54 code = -2 val = 1
received signal 54 code = -2 val = 0
…
Am I right?

2.	You explained internal procedure of signal delivery. From programmer’s point of view, based on help documentation, 
this procedure is not evident. 
3.	In accordance with Murphy's law "Whatever can go wrong will go wrong, and at the worst possible time, in the worst 
possible way." Concerning signals, programmer’s mistakes may occur due to the fact that some people interpret POSIX 
defined real-time signals delivery order in other way as compared with QNX Neutrino implementation. For example,  W. 
Richard Stevens in his book “UNIX Network Programming. Volume 2. Interprocess Communications” consider signal delivery
 order like demonstrate QNX Neutrino caused probably by error in Solaris 2.6. Another example – both  programs from my 
 attachment (with the smallest changes) being launched under Lynx OS  shows strictly order of delivery from small to big
 signal numbers. 

4.	So it is desirable to have neatly stated QNX Neutrino implementation of signal delivery order in help documentation.

5.	Don’t consider my post as aimed against QNX Neutrino. It is very good RTOS! We use it in student training for 
several years.

6.	I apologize for my bad poor English.

Oleg.
Re: signal priorities issue  
I spotted the error in s5_sighandler.c - it's clearing the sa_mask value of the sigaction.

That means that no signals are masked during the execution of the signal handler.

Setting the sa_mask correctly produces the expected results from the UNP book.

Cheers,

Colin

Oleg Nikolsky wrote:
> Colin Burgess, thank You for reply.
> 
> I understood Your explanation, maybe not quite perfectly. So I have some questions and objections.
> 
> 1.	If signals are ‘stacked’, it seems they must be delivered in strictly reverse order, i.e. 
> Sent:
> signal sent: 56 with val = 0
> signal sent: 56 with val = 1
> signal sent: 56 with val = 2
> signal sent: 55 with val = 0
> signal sent: 55 with val = 1
> signal sent: 55 with val = 2
> signal sent: 54 with val = 0
> signal sent: 54 with val = 1
> signal sent: 54 with val = 2
> …
> Received:
> received signal 56 code = -2 val = 2
> received signal 56 code = -2 val = 1
> received signal 56 code = -2 val = 0
> received signal 55 code = -2 val = 2
> received signal 55 code = -2 val = 1
> received signal 55 code = -2 val = 0
> received signal 54 code = -2 val = 2
> received signal 54 code = -2 val = 1
> received signal 54 code = -2 val = 0
> …
> Am I right?
> 
> 2.	You explained internal procedure of signal delivery. From programmer’s point of view, based on help documentation,
 this procedure is not evident. 
> 3.	In accordance with Murphy's law "Whatever can go wrong will go wrong, and at the worst possible time, in the worst 
possible way." Concerning signals, programmer’s mistakes may occur due to the fact that some people interpret POSIX 
defined real-time signals delivery order in other way as compared with QNX Neutrino implementation. For example,  W. 
Richard Stevens in his book “UNIX Network Programming. Volume 2. Interprocess Communications” consider signal delivery
 order like demonstrate QNX Neutrino caused probably by error in Solaris 2.6. Another example – both  programs from my 
 attachment (with the smallest changes) being launched under Lynx OS  shows strictly order of delivery from small to big
 signal numbers. 
> 
> 4.	So it is desirable to have neatly stated QNX Neutrino implementation of signal delivery order in help documentation
.
> 
> 5.	Don’t consider my post as aimed against QNX Neutrino. It is very good RTOS! We use it in student training for 
several years.
> 
> 6.	I apologize for my bad poor English.
> 
> Oleg.
> 
> _______________________________________________
> QNX Software Development Platform Pre-Releases
> http://community.qnx.com/sf/go/post27915

-- 
cburgess@qnx.com
Re: signal priorities issue  
Colin, thank You for reply.

Yes, after I corrected error that You spotted, program works rightly.
But it is ruefully that POSIX allows so free interpretation of it’s regulations. That’s why it is advisable add 
requirement of RT signals blocking using sigaction sa_mask in sigqueue() help topic. It may prevent errors while porting
 programs from other POSIX oriented RTOS (Lynx OS for example, as I mentioned in previous post).

Yours sincerely ,
Oleg.