本文介绍了C 中的循环/计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 C 中创建计时器?
How does one create a timer in C?
我想要一段代码来连续从 gps 解析器输出中获取数据.
I want a piece of code to continuously fetch data from a gps parsers output.
是否有很好的库,还是应该自己编写?
Are there good libraries for this or should it be self written?
推荐答案
可用的最简单方法:
#include <pthread.h>
void *do_smth_periodically(void *data)
{
int interval = *(int *)data;
for (;;) {
do_smth();
usleep(interval);
}
}
int main()
{
pthread_t thread;
int interval = 5000;
pthread_create(&thread, NULL, do_smth_periodically, &interval)
...
}
这篇关于C 中的循环/计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!