tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: sigwait() and SIGSEGV



On Monday 14 December 2009 13:18:18 Sad Clouds wrote:
> OK, the problem seems to be:
> 
> If all threads block all signals and then only one thread calls sigwait(),
> then the thread waiting on sigwait() will only get those signals that are
>  sent to the whole process, not individual threads.
> 
> So if one thread calls 'pthread_kill(pthread_self(), SIGUSR1)' that signal
> will be pending for this particular thread and will not be delivered to the
> thread waiting on sigwait().
> 
> Is this the correct Posix behavior?

Well after digging around, I think this is how it's implemented on most Unix 
systems. There are synchronous and asynchronous signals. Synchronous signals 
like SIGSEGV, SIGILL, SIGBUS, SIGFPE, etc are only delivered to the thread 
that caused it, so if you want to handle those signals you need to establish a 
process-wide signal handler with sigaction(). Each threads then will call the 
same signal handler if it receives that particular signal.

Asynchronous signals can be handled by a separate thread, which calls 
sigwait() and blocks until a signal arrives. To handle those signals you need 
to block them in all threads in your process, including the thread calling 
sigwait(). This will only work if an asynchronous signal is sent to the whole 
process, if one thread calls pthread_kill() to send a signal to another 
thread, that signal will be treated as synchronous.


Home | Main Index | Thread Index | Old Index