Linux多任务编程--线程通信(条件变量示例)
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
inc_count(): thread 1, count = 13, unlocking mutex
inc_count(): thread 0, count = 14, unlocking mutex
inc_count(): thread 1, count = 15, unlocking mutex
条件变量示例 ✓输出结果
inc_count(): thread 0, count = 5, unlocking mutex inc_count(): thread 0, count = 6, unlocking mutex inc_count(): thread 1, count = 7, unlocking mutex
生产者/消费者问题—PV原语操作
生产者/消费者问题 ✓采用多线程技术解决生产者/消费者问题 ➢也称有界缓冲区问题 •多个生产者线程向缓冲区中写数据 •多个消费者线程从缓冲区中读取数据 ➢生产者线程和消费者线程必须满足 •生产者写入缓冲区的数目不能超过缓冲区容量 •消费者读取的数目不能超过生产者写入的数目
Linux多任务编程
8
线程管理
Linux多任务编程
----线程通信(条件变量示例)
Linux多任务编程
2
线程通信
条件变量示例
Linux多任务编程
3
线程通信
条件变量示例 (接上页)
Linux多任务编程
4
线程通信
条件变量示例 (接上页)
Linux多任务编程
5
线程通信
条件变量示例 (接上页) (接上页)
Linux多任务编程 inc_count(): thread 0, count = 1, unlocking mutex Starting watch_count(): thread 2
inc_count(): thread 0, count = 8, unlocking mutex
inc_count(): thread 1, count = 9, unlocking mutex
inc_count(): thread 0, count = 10, unlocking mutex
inc_count(): thread 1, count = 11, unlocking mutex
inc_count(): thread 0, count = 12 Threshold reached.
inc_count(): thread 0, count = 12, unlocking mutex
watch_count(): thread 2 Condition signal received.
inc_count(): thread 1, count = 19, unlocking mutex
inc_count(): thread 1, count = 20, unlocking mutex
Main(): Waited on 3 threads. Done.
Linux多任务编程
7
线程通信
inc_count(): thread 0, count = 16, unlocking mutex
inc_count(): thread 1, count = 17, unlocking mutex
inc_count(): thread 0, count = 18, unlocking mutex
6
inc_cowenku.baidu.comnt(): thread 1, count = 2, unlocking mutex
线程通信
inc_count(): thread 0, count = 3, unlocking mutex inc_count(): thread 1, count = 4, unlocking mutex