使用 sigwait 时我们应该关心 EINTR 吗?

Maj*_*imi 5 c multithreading signals

在多线程应用程序中,所有线程都会阻止所有信号,并且单个线程在循环中执行信号处理sigwait。现在我们应该考虑在其他线程中EINTR使用像read和一样的系统调用吗?write

while (true)
{
    num = read(fd, buf, size);
    if (num == -1 && errno == EINTR)
        continue;
    else if (num > 0)
        /* handle the buf and read more */
}
Run Code Online (Sandbox Code Playgroud)

caf*_*caf 4

EINTR仅当系统调用被信号处理程序中断时才返回。如果所有信号都被阻止在进行系统调用的线程的信号掩码中,那么这种情况就不会发生。