免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1385 | 回复: 3
打印 上一主题 下一主题

多线程编程求教 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 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);
}
请问各位:这段代码有问题吗,为什么得不到预期的效果,搞了一天了,郁闷死了。

论坛徽章:
1
双子座
日期:2015-01-04 14:25:06
2 [报告]
发表于 2009-10-21 22:43 |只看该作者
你期望的结果是什么?
实际的结果又是什么呢?

论坛徽章:
1
双子座
日期:2015-01-04 14:25:06
3 [报告]
发表于 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;

论坛徽章:
0
4 [报告]
发表于 2009-10-21 23:07 |只看该作者
三楼果然是高手,多谢!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP