- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
sigaddset()
与 pthread_sigadd()
函数有什么区别?在下面的代码中,如果 pthread_sigmask()
函数调用未注释,则信号将会到来。
sigemptyset(&signal_set);
if( sigaddset(&signal_set,SIGUSR1) == -1){
printf"sigaddset() retuned error number %d\n",errno);
}
//pthread_sigmask ( SIG_BLOCK, &signal_set, NULL );
while(1){
if(sigwait(&signal_set, &sig_number) == 0){
printf("Got signal\n");
}
}
最佳答案
sigaddset()
和 pthread_sigadd()
一起使用,但执行不同的操作。
sigaddset()
:http://man7.org/linux/man-pages/man3/sigsetops.3.html :
These functions allow the manipulation of POSIX signal sets.
sigaddset()
andsigdelset()
add and delete respectively signal from set.
pthread_sigadd()
:设置信号后,可以通过 sigprocmask()
/pthread_sigmask()
屏蔽它。
http://man7.org/linux/man-pages/man2/sigprocmask.2.html ,
http://man7.org/linux/man-pages/man3/pthread_sigmask.3.html :
sigprocmask()
[as well aspthread_sigmask()
] is used to fetch and/or change the signal mask of the calling thread. The signal mask is the set of signals whose delivery is currently blocked for the caller (see alsosignal(7)
for more details).
关于您发布的代码,收到信号是其预期的工作方式。
http://pubs.opengroup.org/onlinepubs/009695399/functions/sigwait.html :
The signals defined by
set
shall have been blocked at the time of the call tosigwait()
; otherwise, the behavior is undefined.
因此,您必须始终先阻止信号,然后等待它们。
关于linux - sigaddset 与 pthread_sigmask,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30193762/
这是 this question 的后续内容我已经查看了相关问题。 我仍在尝试在收到 SIGTERM 时进行一些清理,然后达到 TERM 的效果,这是进程中没有线程等待时的默认行为对于信号,和并且没有
我有这样一个信号处理程序: void my_signal_handler(int signo ) { sigset_t sa_mask; sigsetemptyset(&sa_mask
在其中一个线程中,我必须等待特定的实时信号,但我不明白为什么首先我必须在等待特定信号之前为线程设置整个 sigmask。 sigset_t signals; siginfo_t inf
我一直在 Linux 下开发一个多线程程序,对信号处理有特殊要求。例如,我需要程序打印单个 Ctrl-C 输入的统计信息。 我使用 pthread_sigmask 和 sigwait 实现了这一点,即
我正在使用 Linux 并尝试与信号处理相关的代码。我正在尝试以下代码,但我无法理解此代码的行为。 /**Globally declared variable**/ time_t start,
sigaddset() 与 pthread_sigadd() 函数有什么区别?在下面的代码中,如果 pthread_sigmask() 函数调用未注释,则信号将会到来。 sigemptyset
我有一个多线程程序,它需要每 25 毫秒处理一次由 setitimer() 发送的 Linux 信号 SIGVTALRM。但是我很困惑。我不知道为什么我需要使用 Pthread_sigmask() 来
我的应用程序有时会因 SIGIO 或 SIGUSR1 信号而终止,即使我已经阻止了这些信号。 我的主线程从阻塞 SIGIO 和 SIGUSR1 开始,然后进行 2 个 AIO 读取操作。这些操作使用线
pthread_sigmask 似乎不适用于 Android。该问题似乎已在 2 年前报告过 here但一直没有得到开发商的回应。我遇到了一个非常相似的问题(我的代码在下面供引用)。我做错了什么,还是
我正在实现一个简单的计时器,它会在到期时抛出一个 RT 信号。我想要做的是注册一个信号处理程序(使用 sigaction),它在信号发生时被调用。同时,主代码等待直到使用 sigwaitinfo 调用
在程序中,SIGCHLD 被主线程阻塞,然后 线程“THREAD_1”正在执行 sigwait(), 线程“THREAD_2” fork 一个子进程并杀死它,在这个线程中我调用了 pthread_si
在我正在处理的代码库中,所有线程控制都是使用 std::thread 完成的和相关对象,而不是使用 pthread直接地。 但是,我没能找到 pthread_sigmask 的 C++ 等价物,所以我
我有一个通过第 3 方库访问硬件资源 (SPI) 的库。我的库以及 SPI 资源被多个进程访问,所以我需要用信号量锁定资源,锁定函数如下: static int spi_lock(void) {
1) 我是 std::thread 的新手,我想知道调用 pthread_sigmask() 是否是一个好习惯阻止由 std::thread 创建的特定 线程中的某些信号. 我不希望新线程接收SIGT
我正在尝试使用cargo install diesel_cli安装diesel_cli crate ,但是我一直收到此错误: = note: /usr/bin/ld: /usr/lib/libpq
我是一名优秀的程序员,十分优秀!