The POSIX solution to handling signals on MT

The good news is that the POSIX committee has come up with a recommendation to the developers of MT applications for signal-handling. This solution rests on an interesting design fact; although a process has a table of signal dispositions (set up by the kernel and the sigaction(2) system call), every thread within the process has its own discrete signal mask (using which it can selectively block signals) and signal pending mask (by which the kernel remembers which signals are pending delivery to the thread).

Knowing this, the POSIX standard recommends that a developer handle signals in a pthreads application as follows:

  • Mask (block) all signals in the main thread.
  • Now any thread created by main ...

Get Hands-On System Programming with Linux now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.