【问题标题】:Can sigqueue be used with pthreads?sigqueue 可以与 pthread 一起使用吗?
【发布时间】:2014-02-08 20:16:56
【问题描述】:

可以在 multi-threading 中使用 sigqueue 代替 pthread_kill() ,因为我想在 sigqueue 中使用 (const union sigval value) 。我的 linux 中没有 pthread_sigqueue()。

【问题讨论】:

    标签: c++ c linux pthreads posix


    【解决方案1】:

    在 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);
    }
    

    【讨论】:

      猜你喜欢
      • 2010-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-15
      • 2018-02-16
      • 2020-06-30
      • 2014-11-15
      • 2011-12-07
      相关资源
      最近更新 更多