我正在尝试使用 POSIX 计时器,但我的代码无法运行。
timer_t id_timer_;
// some code. timer_create(), etc.
void timerPeriod (unsigned long sec, unsigned long nsec)
{
struct itimerspec myperiod;
myperiod.it_interval.tv_sec = sec;
myperiod.it_interval.tv_nsec = nsec;
myperiod.it_value.tv_sec = sec;
myperiod.it_value.tv_nsec = nsec;
if (timer_settime (&id_timer_, 0, &myperiod, 0))
perror("timer_settime");
}
它返回timer_settime: Invalid argument
,而参数对我来说看起来不错。
我也尝试过timer_settime(id_timer_, 0, &myperiod, 0)
(没有&之前id_timer_
),我认为这是使用的好方法timer_settime()
:分段错误......
有什么线索吗?