Chinaunix

标题: 多线程编程求教 [打印本页]

作者: sky_bj2008    时间: 2009-10-21 21:45
标题: 多线程编程求教
#include<time.h>
#include <pthread.h>
#include <stdio.h>

int main()
{
   pthread_cond_t cond;
   pthread_mutex_t mutex;
   struct timespec timeout;

   timeout.tv_sec=9;
   timeout.tv_nsec=0;

   pthread_mutex_init(&mutex,NULL);
   pthread_cond_init(&cond,NULL);

   pthread_mutex_lock(&mutex);
   pthread_cond_timedwait(&cond,&mutex,&timeout);
   printf("OK\n");
   pthread_mutex_unlock(&mutex);
}
请问各位:这段代码有问题吗,为什么得不到预期的效果,搞了一天了,郁闷死了。
作者: yecheng_110    时间: 2009-10-21 22:43
你期望的结果是什么?
实际的结果又是什么呢?
作者: yecheng_110    时间: 2009-10-21 22:44
The   pthread_cond_timedwait()   function   shall   be   equivalent  to
       pthread_cond_wait(), except that an error is returned if  the  absolute
       time  specified  by  abstime  passes  (that  is,  system time equals or
       exceeds abstime) before the condition cond is signaled or  broadcasted,
       or if the absolute time specified by abstime has already been passed at
       the time of the call.

我想是这个意思
timeout.tv_sec=time(NULL)+9;
作者: sky_bj2008    时间: 2009-10-21 23:07
三楼果然是高手,多谢!




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2