coo*_*ker 2 linux asynchronous
我想使用异步计时器,它在到期时触发回调函数.我想要微秒级的精度.我的代码流程就像这样..
timer_t tid;
struct itimerspec val;
val.it_value.tv_sec = 0;
val.it_value.tv_nsec = 100000;
value.it_interval.tv_sec = 0;
value.it_interval.tv_nsec = 100000;
timer_create (CLOCK_REALTIME, NULL, &tid);
timer_connect (tid, myfunc,0);
timer_settime (tid, 0, &val, NULL);
and write my handle function:
myfunc(){
blah blah blah...
}
Run Code Online (Sandbox Code Playgroud)
我认为在最近的Linux版本中没有使用timer_connect.我有替代方案吗?
谢谢,
实际上,在最近的Linux版本中不存在timer_connect.实际上,我很确定它在任何Linux版本中都不存在,不管是近期与否.一些谷歌搜索表明它是在VxWorks中发现的东西.它在POSIX中也找不到,FWIW.
在Linux(和POSIX)中,您可以提供指向struct sigevent的指针作为timer_create()的第二个参数(在您的示例中为NULL).struct sigevent又有一个成员(*sigev_notify_function),顾名思义,它是在计时器到期时调用的函数(这要求通知方法是SIGEV_THREAD).