int WaitCond(unsigned short v,unsigned long timeout_ms,unsigned long second)
{
pthread_mutex_lock(&mutex);
timeval tv;
gettimeofday(&tv,NULL);
tv.tv_sec+=second;
tv.tv_sec+=(tv.tv_usec+timeout_ms*1000l)/1000000l;
tv.tv_usec=(tv.tv_usec+timeout_ms*1000l)%1000000l;
timespec ts;
TIMEVAL_TO_TIMESPEC(&tv,&ts);
// clock_gettime(CLOCK_REALTIME,&testtime);
// printf("%d %d\n",testtime.tv_sec,testtime.tv_nsec);
pthread_cond_timedwait(&WaitCond,&WaitMutex,&ts);//有时调用这就死机了。
printf("abcd\n");
pthread_mutex_unlock(&mutex);
return 1;
}
以上是我的函数信息,请大家提出意见与建议啊。。不管对的错的,都谢谢大家了。
|