条件变量本质-Problem statement-while not( P ) do skip

本文探讨了条件变量的工作原理及其在多线程环境中的应用。条件变量作为同步机制之一,能够解决互斥条件下的线程等待问题。文章进一步解释了为何简单的忙等循环无法解决问题,并介绍了如何使用条件变量来实现线程间的有效同步。

条件变量相当于订阅-发布机制;

或者相当于同步的通知机制;

 

订阅和发布具有先后顺序;所以需要互斥量来维护顺序。

顺序不对,存在信号丢失问题。

 

Problem statement[edit]

For many applications, mutual exclusion is not enough. Threads attempting an operation may need to wait until some condition P holds true. A busy waiting loop

   while not( P ) do skip

will not work, as mutual exclusion will prevent any other thread from entering the monitor to make the condition true.

 

https://en.wikipedia.org/wiki/Monitor_(synchronization)#Condition_variables

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值