Page 1 of 1

posix blocked signals and pthread_kill

Posted: Sun Apr 24, 2016 12:36 pm
by Hellbender
Hi.

I'm trying to combine information at Signal Concepts and pthread_kill.

What puzzles me a bit is what should happen when a signal send with phread_kill is blocked by the thread. What I gather from those documents, is that the behaviour should be as if the signal was sent using the kill function, that is, the signal should be delivered to any thread that does not block it, any threads waiting the signal, or be pending on the process until such thread appears. This is not very clear though, so I'm kind of worried that I'm missing something here.

I'd be keep to implement the former, as signal delivery design would be easier if 'pthread_kill' could forward any blocked signals to 'kill'. Anyone with some insight on proper interpretation of the standard on this part?

Re: posix blocked signals and pthread_kill

Posted: Sun Apr 24, 2016 3:45 pm
by gerryg400
My understanding is that if a thread blocks a signal then when that signal is sent to the thread it will be blocked. If the signal is sent to the process then the kernel will look for any thread that has that signal not blocked.

Re: posix blocked signals and pthread_kill

Posted: Sun Apr 24, 2016 11:38 pm
by Hellbender
gerryg400, although I might not like it, I tend to agree. It would be clear if these italic parts to the specs:
If the action associated with a blocked signal is anything other than to ignore the signal, and if that signal is generated for the thread, the signal shall remain pending until it is unblocked by the thread, it is accepted when it is selected and returned by a call to the sigwait() function by the thread, or the action associated with it is set to ignore the signal.
Also, the next statement is clear that multiple threads are considered when signal is generated for the process, implicitly excluding the signals generated for a thread:
Signals generated for the process shall be delivered to exactly one of those threads within the process which is in a call to a sigwait() function selecting that signal or has not blocked delivery of the signal.
Damn. This means that I need pending signal queues for a process and each thread separately, and need to check both queues to see which signal should be delivered next. Another layer of added complexity..