信号掩码是特定于线程的,这意味着阻止信号不会阻止它被传递到未阻止该信号的另一个线程。当执行进入处理程序函数时(假设没有 SA_NODEFER),“当前”信号将被阻塞。
这是否意味着当前进程中的所有线程都会被阻止,或者下一个此类信号可能会传递到另一个线程(尽管它仍在第一个线程中处理)?
最佳答案
阅读man sigaction
:
sa_mask
specifies a mask of signals which should be blocked (i.e., added to the signal mask of the thread in which the signal handler is invoked) during execution of the signal handler. In addition, the signal which triggered the handler will be blocked, unless theSA_NODEFER
flag is used.
这听起来像是当前处理的信号的屏蔽仅影响处理线程,因此其他线程可以处理更多信号。
我认为多线程系统通常会阻止所有线程的所有信号,除了一个(或多个)专用信号处理线程(例如轮询 signalfd 的线程)。这样您就不必担心信号落在某个不可预测的线程上。
关于c - 信号 "auto-block"(当执行进入处理程序函数时)是否会阻止另一个此类信号传递到另一个线程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51431135/