免费注册 查看新帖 |

Chinaunix

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

多线程发信号的问题 [复制链接]

论坛徽章:
1
15-16赛季CBA联赛之佛山
日期:2015-12-14 17:57:31
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-11-18 17:37 |只看该作者 |倒序浏览
一般是用pthread_cond_signal pthread_cond_wait
也有用sem系列,请问有什么区别。是不是前者封装了后者。

论坛徽章:
0
2 [报告]
发表于 2010-11-18 18:50 |只看该作者
The pthread_cond_signal() function shall unblock at least one of the threads that are blocked on the specified condition variable cond (if any threads are blocked on cond).

If more than one thread is blocked on a condition variable, the scheduling policy shall determine the order in which threads are unblocked. When each thread unblocked as a result of a pthread_cond_broadcast() or pthread_cond_signal() returns from its call to pthread_cond_wait() or pthread_cond_timedwait(), the thread shall own the mutex with which it called pthread_cond_wait() or pthread_cond_timedwait(). The thread(s) that are unblocked shall contend for the mutex according to the scheduling policy (if applicable), and as if each had called pthread_mutex_lock().

论坛徽章:
0
3 [报告]
发表于 2010-11-18 21:06 |只看该作者
你所说的一切跟信号半毛钱关系都没有...

论坛徽章:
1
申猴
日期:2014-02-11 14:50:31
4 [报告]
发表于 2010-11-18 21:22 |只看该作者
用途不同,实现方法也有所不同

论坛徽章:
0
5 [报告]
发表于 2010-11-18 22:37 |只看该作者
pthread_cond_signal pthread_cond_wait,这两个用过,主要用来实现,生产者-消费者模型。生产者产生任务后,调用pthread_cond_signal通知消费者。消费者消费完,调用pthread_cond_wait等待新的任务。肯定还有别的用处,但都是实现线程同步的。

sem系列的函数,没经验。

论坛徽章:
0
6 [报告]
发表于 2010-11-19 08:47 |只看该作者
不是前者封装了后者,是后者封装了前者。{:3_182:}

论坛徽章:
1
15-16赛季CBA联赛之佛山
日期:2015-12-14 17:57:31
7 [报告]
发表于 2010-11-19 09:54 |只看该作者
跟信号半毛钱没有,为何函数里有个signal单词呢?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP