日期:2014-05-16 浏览次数:20565 次
#include <stdio.h> #include <time.h> #include <sys/time.h> #include <stdlib.h> #include <signal.h> #include <stdio.h> #include <unistd.h> #include <string.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <sys/ioctl.h> #include <sys/time.h> int g_timerStartFlag; inline unsigned long get_time() ///return ms; { struct timeval tv = {0}; gettimeofday(&tv, 0); return tv.tv_sec*1000+tv.tv_usec/1000; } int count; void *createTimer(void *arg) { int timecnt=0; pthread_detach(pthread_self()); unsigned long lasttime=get_time(); while(g_timerStartFlag) /// { unsigned long nowtime; nowtime=get_time(); if(nowtime-lasttime>=500) ///500ms { printf("timeout------\n"); lasttime = nowtime; } } fprintf(stderr,"break;"); return NULL; } void libck_createTimerAndStart(void) { pthread_t timeid; g_timerStartFlag=1; pthread_create(&timeid, NULL, &createTimer, NULL); //// } int main() { int i; libck_createTimerAndStart(); while(1) { for(i=0;i<1000000;i++); } return 0; }