linux - Linux poll(2) 虽然所有信号都被阻塞但被中断
问题描述
当我复杂的多线程程序调用 poll(2) 时,调用被中断——即使所有信号都已被阻塞。此外,从不调用所有信号的已安装信号处理程序。我想了解可能导致这种情况的一些想法。
该程序太复杂而无法包含,但这里有一个说明问题的代码片段:
#define _XOPEN_SOURCE 700
#undef NDEBUG
#include <assert.h>
#include <poll.h>
#include <pthread.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
void foo(const int sock)
{
sigset_t allSigs;
sigfillset(&allSigs);
int status = pthread_sigmask(SIG_BLOCK, &allSigs, NULL); // Blocks all signals
assert(status == 0);
{
sigset_t sigset;
status = sigpending(&sigset);
assert(status == 0);
for (int sigNum = 1; sigNum < _NSIG; ++sigNum)
if (sigismember(&sigset, sigNum))
fprintf(stderr, "Signal %d is pending", sigNum); // Prints nothing
}
struct pollfd pfd;
pfd.fd = sock;
pfd.events = POLLRDNORM;
errno = 0; // Just to make sure
status = poll(&pfd, 1, 30000); // All-signals signal-handler never called
if (status < 0)
perror("poll() failure"); // Prints "poll() failure: Interrupted system call"
}
我知道,这是不可能的——但它正在发生。
如果您对可能导致此问题的原因有任何想法,我想听听他们的意见。
这是我的环境:
$ cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
$ uname -a
Linux gilda 3.10.0-862.11.6.el7.x86_64 #1 SMP Tue Aug 14 21:49:04 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
$ gcc -dumpversion
4.8.5
解决方案
推荐阅读
- microsoft-graph-api - 如何通过 Microsoft Graph Api 正确请求 Sharepoint Online 站点权限
- java - java中的电子邮件验证循环不起作用
- excel - 将“findnext”功能合并到现有的“查找”代码中?
- tensorflow - 如何使用 CNN 和 LSTM 元素改进文本分类模型?
- r - 如何使用 autoplot 和 geom_scatterpie
- typescript - 如何连接 observables 与下一个观察者发出
- r - 变量列表的迭代函数
- php - Advance Custom Field Pro 插件 (WordPress):无法通过 PHP 加载字段定义
- pytorch - 输入张量大小不继承训练数据集标签计数
- database - 将html列更新为null可以节省空间吗?