This article is from the Threads Programming FAQ, by Bryan O'Sullivan firstname.lastname@example.org with numerous contributions by others.
Signals and threads do not mix well. A lot of programmers start out by
writing their code under the mistaken assumption that they can set a
signal handler for each thread; this is not the way things work. You
can "block" or "unblock" signals on a thread-by-thread basis, but this
is not the same thing.
When it comes to dealing with signals, the best thing you can do is
create a thread whose sole purpose is to handle signals for the entire
process. This thread should loop calling sigwait(2); this allows it to
deal with signals synchronously. You should also make sure that all
threads ("including" the one that calls sigwait) have the signals you
are interested in handling blocked. Handling signals synchronously in
this way greatly simplifies things.
Note, also, that sending signals to other threads within your own
process is not a friendly thing to do, unless you are careful with
signal masks. For an explanation, see the section on asynchronous
Finally, using sigwait and installing signals handlers for the signals
you are sigwaiting for is a bad idea.