posix blocked signals and pthread_kill

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Hellbender
Member
Member
Posts: 63
Joined: Fri May 01, 2015 2:23 am
Libera.chat IRC: Hellbender

posix blocked signals and pthread_kill

Post 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?
Hellbender OS at github.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: posix blocked signals and pthread_kill

Post 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.
If a trainstation is where trains stop, what is a workstation ?
Hellbender
Member
Member
Posts: 63
Joined: Fri May 01, 2015 2:23 am
Libera.chat IRC: Hellbender

Re: posix blocked signals and pthread_kill

Post 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..
Hellbender OS at github.
Post Reply