Linux与clock_nanosleep一起睡觉 [英] linux sleeping with clock_nanosleep
本文介绍了Linux与clock_nanosleep一起睡觉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用clock_nanosleep等待1微秒。据我所知,我必须给绝对时间作为输入。在这种情况下,以下代码可以吗?
I want to use clock_nanosleep for waiting of 1 microsec.. As far as I understand, I have to give an absolute time as input. Is the following code okay in this case?
deadline.tv_sec = 0;
deadline.tv_nsec = 1000;
clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &deadline, NULL);
推荐答案
据我理解,我必须给绝对的时间作为输入。
As far as I understand, I have to give an absolute time as input.
不,标志
参数可让您选择相对或绝对时间。您想要
No, the flags
argument allows you to choose relative or absolute time. You want
clock_nanosleep(CLOCK_REALTIME, 0, &deadline, NULL);
从现在开始指定一微秒。
to specify one microsecond from now.
这篇关于Linux与clock_nanosleep一起睡觉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文