多线程互斥 基于c++11
来源:互联网 发布:java布局思想 编辑:程序博客网 时间:2024/05/24 06:45
#include <thread>#include <iostream>#include <mutex>std::mutex m;int count=10;bool debug=true;//控制 是否使用互斥using std::cout;using std::endl;void hello1(){ if(debug) m.lock(); for(int i=0;i<1000;i++) { count++; cout<<"1"<<std::flush; } if(debug) m.unlock();}void hello2(){ if(debug) m.lock(); for(int i=0;i<1000;i++) { count--; cout<<"2"<<std::flush; } if(debug) m.unlock();}int main(){ std::thread t1(hello1),t2(hello2); t1.join(); t2.join(); std::cout<<"Main Thread "<<count<<std::endl; return 0;}
0 0
- 多线程互斥 基于c++11
- Linux C 多线程【4】--线程互斥
- 多线程互斥
- 多线程互斥同步
- 多线程互斥同步
- 多线程同步互斥
- 多线程互斥--mutex
- 多线程互斥
- 【多线程】传统 -- 互斥
- [C#] C#多线程学习(六) 互斥对象
- iOS (objective-c) 中的多线程互斥同步问题
- iOS (objective-c) 中的多线程互斥同步问题
- iOS (objective-c) 中的多线程互斥同步问题
- Objective-C多线程同步互斥及锁
- iOS (objective-c) 中的多线程互斥同步问题
- iOS (objective-c) 中的多线程互斥同步问题
- iOS (objective-c) 中的多线程互斥同步问题2
- Linux C——多线程的同步和互斥
- RBBAnimation,让你使用关键帧动画更便利
- 朱光潜给青年的十二封信 之 谈升学和选课
- AFNetworking 2.0
- jfinal+bae部署
- 分类的IP地址(四)
- 多线程互斥 基于c++11
- 背包专辑-基础篇(持续更新中)
- GCDObjC
- char*, wchat_t*互转 及 A2T, T2A宏及其实现原理
- c# 实现datagridview 用回车向右移动,到头换行,支持编辑模式
- java阻塞队列以及非阻塞队列
- LeetCode(Remove Duplicates from Sorted List) 两道删除排序链表中重复数字
- asp.net服务器控件生命周期
- 第五周学习内容