- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用 Linux 并尝试与信号处理相关的代码。我正在尝试以下代码,但我无法理解此代码的行为。
/**Globally declared variable**/
time_t start, finish;
struct sigaction sact;
sigset_t new_set, old_set,test;
double diff;
/**Function to Catch Signal**/
void catcher( int sig )
{
cout<< "inside catcher() function\n"<<endl;
}
void Initialize_Signalhandler()
{
sigemptyset( &sact.sa_mask );
sact.sa_flags = 0;
sact.sa_handler = catcher;
sigaction( SIGALRM, &sact, NULL );
sigemptyset( &new_set );
sigaddset( &new_set, SIGALRM );
}
/**Function called by thread**/
void *threadmasked(void *parm)
{
/**To produce delay of 10sec**/
do {
time( &finish );
diff = difftime( finish, start );
} while (diff < 10);
cout<<"Thread Exit"<<endl;
}
int main( int argc, char *argv[] ) {
Initialize_Signalhandler();
pthread_t a;
pthread_create(&a, NULL, threadmasked, NULL);
pthread_sigmask( SIG_BLOCK, &new_set, &old_set);
time( &start );
cout<<"SIGALRM signals blocked at %s\n"<< ctime(&start) <<endl;
alarm(2); //to raise SIGALM signal
/**To produce delay of 10sec**/
do {
time( &finish );
diff = difftime( finish, start );
} while (diff < 10);
return( 0 );
}
甚至认为我正在使用“pthread_sigmask(SIG_BLOCK, &new_set, &old_set)”。它没有阻挡信号。但是如果我删除“pthread_create(&a, NULL, threadmasked, NULL);”它工作正常并阻止了信号。我在这里观察到的另一件事是,如果我将 pthread_sigmask 更改为 sigprocmask,行为保持不变。
最佳答案
线程从创建它们的线程继承信号掩码。
因此,当您的代码调用 pthread_sigmask()
after 它调用 pthread_create()
时,新创建的线程不会修改其信号掩码.
像这样更改你的代码,让事情按你预期的那样工作:
...
pthread_sigmask( SIG_BLOCK, &new_set, &old_set);
pthread_t a;
pthread_create(&a, NULL, threadmasked, NULL);
...
关于c++ - pthread_sigmask :unusual behavior,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14495192/
我正在尝试使用两个线程的代码,一个线程递增共享长变量,另一个线程递减 var。 class Shared { private long a; public void incr() {
我正在使用 Linux 并尝试与信号处理相关的代码。我正在尝试以下代码,但我无法理解此代码的行为。 /**Globally declared variable**/ time_t start,
对于一个涉及从光谱数据计算键长的项目,我使用 Solve[] 来求解一个相当简单的未知方程。当我更改输入时,我开始注意到“异常”行为。具体来说,当我更改一个数字并解决时,结果就是之前的答案。然而,再次
请帮我找到这个“段错误:11”。 argv 输入看起来不错。顺便说一句,这是一个就餐哲学家问题。它在一小时前工作,但在 minix 机器上,但现在在 Unix 机器上它无法运行。请帮我解决这个愚蠢的错
场景:我向服务器请求零件。它给了我这个(它是伪造的,但代表了我正在看的东西): { PartNumber : "XYZ", Description: "ABCFOO", ProductClass: "
这是摘自“JavaScript,权威指南”中有关 arguments 对象的核心 JavaScript 引用的一段话: In non-strict mode, the Arguments object
程序的输出是这样的: 虽然内容正确 (目前仅在尝试解密产生错误结果时) 但是为什么会出现这个错误? udit@udit-Dabba /opt/lampp/htdocs $ ./a.out Error
我有一个购物 list 应用程序,我正计划将 Core Data 与它一起使用。 我有一个杂货店 Item 抽象类,它具有三个子类:RecipeItem、QuickAddItem 和 HybridIt
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicate: What does the ',' operator do in C? 好吧,我今天接受了采访,他们问我下面
我有一个简单的“用户”集合,现在我只有 2 个文档。 { "_id": ObjectId("4ef8e1e41d41c87069000074"), "email_id": {
在行:std::ifstream fileOpen(file.c_str()); 在下面的函数中程序崩溃并给我这个错误: This application has requested the Runt
我有一个未排序的数组,包含 10,000 个从 0 到 9,999 的整数。我想对这个未排序的数组应用合并排序,我编写了以下代码- import sys def merge_sort(data):
当我关闭 Qt 程序 (g++ 4.4.0) 时,出现 Microsoft Visual C++ Runtime Library 错误“此应用程序已请求运行时以异常方式终止它”。但是当我在调试器中运行
我正在使用 Instagram API 开发自己的安卓应用。在我家的 Wi-Fi 上,一切都很好。它已经过 100 多次测试。今天我尝试通过我公司的公司 Wi-Fi 将我的 Sandbox 客户端连接
我有一个5张谷歌电子表格和一个应用程序脚本项目,简而言之就是这样做的:。当我为x调用它时,它成功地返回了正确的数组。不幸的是,对于y和z,它都在前15个元素之后停止。是否有解决此问题的方法?这一切为什
我发现自己负责继续开发一个不是我最初设计的系统,并且不能问最初的设计师为什么要做出某些设计决定,因为他们已经不在了。我是一个设计问题的初级开发人员,所以当我开始这个项目时我真的不知道该问什么,这是我的
我的 Meson项目我有一个位于“不寻常”位置的依赖项: /opt/MyDependence/lib/libmyLib.so /opt/MyDependence/include/myLib.hpp 我
我有这个 Pandas DataFrame,有两列 label 和 time >>> df = pd.DataFrame([{'a':{'tier':'one','app':'frontend'},'
“Scheme 编程语言第 4 版” 第 3.3 节 Continuations给出了以下示例: (define product (lambda (ls) (call/cc (
我有一个 C++ 程序,它在进程启动后立即给出此错误 - 显然是在任何用户代码执行之前。它仅在启用内联时发生。即使内置了调试符号,我也无法进入代码。当我在 Visual Studio 中按下 F10
我是一名优秀的程序员,十分优秀!