循环/定时器使用C [英] Loops/timers in C
本文介绍了循环/定时器使用C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
一个人如何用C创建一个定时器?
How does one create a timer in C?
我想要一张code的连续从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?
推荐答案
最简单的方法可供选择:
Simplest method available:
#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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文