是否可以使用 sigqueue 代替 pthread_kill()
在多线程中,因为我想在 sigqueue 中使用 (const union sigval value
)。我没有 pthread_sigqueue()
在我的 Linux 中。
最佳答案
在 Linux 下,可以使用 gettid()
从内核中提取线程特定的 pid_t
系统调用,然后可以与 sigqueue()
一起使用.然而,这是 Linux 特有的并且非常不可移植。
由于 gettid()
很可能无法通过 Linux 的 libc 使用,您可能希望使用以下代码来实现它:
#define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>
pid_t gettid(void)
{
return syscall(SYS_gettid);
}
关于c++ - sigqueue 可以与 pthreads 一起使用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21651333/