On Dec 30, 5:33 am, James Kanze<james.ka...@gmail.com> wrote:
More generally, you probably don't want to, at least if the goal
is to trigger a clean shutdown. You normally can't start
a clean shutdown at just anytime, and signals arrive
asynchronously. The usual solution depends on the application:
for anything multithreaded under Unix, you can create a special
signal handler thread; signals will generate an event which
unblocks the thread, and the thread can start the clean shutdown
(running as a normal thread, and not as a signal handler). For
single threaded processes, the usual solution is just to have
a global sig_atomic_t initialized to zero, set it to one in the
signal handler, and poll it at appropriate moments.
Wow, I learned a lot from this thread--many thanks, all. James, can
you point me to how to create the signal handler thread that you
describe? I think that I get it in principle, but am having a hard
time imagining how to actually do it.
really quite simple. You just create a thread that blocks on sigwait()
and mask out signals to the other threads. The Solaris man page has an