[置顶] c++多线程(多线程处理vector)
2018-03-03 15:18
239 查看
常规定义:
#include <thread> #include<iostream> #include<windows.h> #include<vector> using namespace std; using namespace 9ce7 std::this_thread; void msg() { MessageBoxA(0, "12345", "678910", 0); } void msgA(int num) { std::cout << get_id() << " num= " << num << std::endl; } void main1() { // thread::hardware_concurrency线程 auto n = thread::hardware_concurrency(); std::cout << n << std::endl;//n的值就是cpu的线程 //获取当前线程编号 std::cout << "thread=" << get_id() << std::endl; thread thread1(msg);//创建多线程 thread thread2(msg); thread1.join();//开始执行 thread2.join(); std::cin.get(); } void main2() { vector<thread *> threads; for (int i = 0; i < 10; i++) { threads.push_back(new thread(msg));//创建线程 } for (auto th : threads) { th->join(); } std::cin.get(); } void main() { vector<thread *> threads; for (int i = 0; i < 10; i++) { threads.push_back(new thread(msgA,i));//创建线程 } for (auto th : threads) { th->join(); } std::cin.get(); }
相关文章推荐
- 同步处理的ArrayList和Vector性能小测试(多线程写法)
- [置顶] java Vector 在多线程使用中需要注意的问题
- 网络多线程 异步 同步处理
- [置顶] spring boot实战之日期处理
- 关于多线程编程您不知道的 5 件事 有关高性能线程处理的微妙之处
- python多线程 实现程序快速处理
- C#多线程处理多个队列的数据
- C#中的多线程超时处理实践
- 谈谈dpdk应用层包处理程序的多进程和多线程模型选择时的若干考虑
- [置顶] android 自定义圆角ImageView以及锯齿的处理
- Java多线程处理大量数据
- Android 多线程处理之多线程用法--线程池
- java 多线程 传参 并发处理
- c# 关于Task类处理多线程的学习
- 多线程问题及处理方法【转】
- Java编程那些事儿98——多线程问题及处理1
- [C/C++标准库]_[初级]_[std::vector的多线程读写问题]
- .Net进阶系列(15)-异步多线程(线程的特殊处理和深究委托赋值)(被替换)
- [置顶] 记录:Android api 24+的TabLayout问题处理
- [置顶] android httpClient 支持HTTPS的2种处理方式