Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
渲染循环linux中的精确间隔计时器_Linux_Timer - Fatal编程技术网

渲染循环linux中的精确间隔计时器

渲染循环linux中的精确间隔计时器,linux,timer,Linux,Timer,在Linux中执行以下操作的最佳方法是什么 while(continue) { render(); //this function will take a large fraction of the framerate wait(); //Wait until the full frame period has expired. } 在windows上,可等待计时器似乎工作得很好(在1毫秒内)。一种方法是使用一个单独的线程,它只是休眠并触发同步机制。然而,我

在Linux中执行以下操作的最佳方法是什么

while(continue)
    {
    render(); //this function will take a large fraction of the framerate
    wait();   //Wait until the full frame period has expired.
    }
在windows上,可等待计时器似乎工作得很好(在1毫秒内)。一种方法是使用一个单独的线程,它只是休眠并触发同步机制。然而,我不知道这里面有多少开销


注意:准确度比高频更重要:频率为1.000 kHz的计时器优先于频率为1 MHz的计时器。

假设您正在寻找C语言的答案:

我不记得精度了,但我记得我曾经在需要高精度时使用过setitimer()函数


下面是一个如何使用它的示例:

如果在单独线程中运行循环的库已经在使用它,会发生什么?嗯,不确定。也许您还可以看看一个名为timer_create()的函数,它似乎更具有线程意识。但我不知道它的准确性也许你还可以看到另一个问题: