【问题标题】:pthread conditions support for CLOCK_TAI对 CLOCK_TAI 的 pthread 条件支持
【发布时间】:2016-07-12 16:52:09
【问题描述】:

我必须遗漏一些东西。我可以使用clock_gettime 获得CLOCK_TAI。但是,当我尝试将 CLOCK_TAI 与 pthread 条件一起使用时,我得到一个 EINVAL。

#include <pthread.h>
#include <stdio.h>

int main()
{
  clockid_t clockTai = 11;

  pthread_cond_t  condition;

  pthread_condattr_t  eventConditionAttributes;
  pthread_condattr_init( &eventConditionAttributes );
  int ret = pthread_condattr_setclock( &eventConditionAttributes, clockTai );

  printf( "%d %d\n", ret, clockTai );

  pthread_cond_init( &condition,
                     &eventConditionAttributes );
  return( 0 );
}

当按如下方式编译时,它会产生以下输出:

g++ -o taiTest taiTest.cxx -lpthread -lrt    
./taitest$ ./taiTest 
    22 11

其中 EINVAL = 22 且 CLOCK_TAI = 11。

这发生在我的 Ubuntu 14.04 系统和使用 Yocto 构建的操作系统的嵌入式 ARM 设备上。

非常感谢这里的任何想法或帮助。提前致谢。

【问题讨论】:

    标签: c time linux-kernel pthreads posix


    【解决方案1】:

    根据手册页,pthread_condattr_setclock() 仅接受一组有限的时钟 ID 值。 CLOCK_TAI 不是其中之一。手册页谈到了系统时钟,这听起来有点模棱两可。 CLOCK_REALTIMECLOCK_MONOTONIC 及其派生值应该是可接受的值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-15
      • 2011-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多