随笔分类 -  C++并行编程

LeetCode 1116. 打印零与奇偶数
摘要:题目链接:https://leetcode-cn.com/problems/print-zero-even-odd/ 代码参考链接:https://leetcode-cn.com/problems/print-zero-even-odd/solution/c-san-chong-fang-shi-b 阅读全文

posted @ 2022-01-05 08:39 xcxfury001 阅读(42) 评论(0) 推荐(0) 编辑

C++多线程编程第十三讲--补充知识
摘要://(1)补充一些知识点 //(1.1)虚假唤醒 // wait(), notify_one(), notify_all() 使用非常频繁的接口 // 虚假唤醒是指没有满足条件的时候被唤醒了。 //(1.2)atomic #include<iostream> #include<thread> #in 阅读全文

posted @ 2021-11-03 08:46 xcxfury001 阅读(12) 评论(0) 推荐(0) 编辑

C++多线程编程第十二讲--windows临界区、其他各种mutex互斥量
摘要://(1)windows临界区 #include<iostream> #include<thread> #include<vector> #include<list> #include<mutex> #include<windows.h> #define _WINDOWS //定义一个开关 usin 阅读全文

posted @ 2021-11-02 08:12 xcxfury001 阅读(63) 评论(0) 推荐(0) 编辑

C++多线程编程第十一讲--std::atomic续谈、std::async深入谈
摘要://(1)原子操作std::atomic续谈 // 原子操作针对++,--,+=,-=,&=,|=,~=是支持的,其他的可能不支持。 #include<iostream> #include<mutex> #include<thread> #include<future> using namespac 阅读全文

posted @ 2021-10-27 21:40 xcxfury001 阅读(38) 评论(0) 推荐(0) 编辑

C++多线程编程第十讲--future其他成员函数、shared_future、atomic
摘要://(1)std::future的其他成员函数 #include<iostream> #include<mutex> #include<thread> #include<future> using namespace std; int my_thread() { cout << "my_thread 阅读全文

posted @ 2021-10-26 08:25 xcxfury001 阅读(46) 评论(0) 推荐(0) 编辑

C++多线程编程第九讲--async、future、packaged_task、promise
摘要://(1)std::async、 std::future创建后台任务并返回值 // async是一个函数模板,用来启动一个异步任务,返回一个future类型的对象。用future // 的get方法来获得线程的返回值。 // 异步任务:自动创建一个线程,并开始执行对应线程的入口函数。 #includ 阅读全文

posted @ 2021-10-21 23:12 xcxfury001 阅读(69) 评论(0) 推荐(0) 编辑

C++多线程编程第八讲--condition_variable、wait、notify_one、notify_all
摘要:/*condition_variable、wait、notify_one、notify_all*/ //(1)条件变量std::condition_variable()、wait()、notify_one()// std::condition_variable()是一个类,需要和互斥量配合工作。 # 阅读全文

posted @ 2021-10-19 08:41 xcxfury001 阅读(272) 评论(0) 推荐(0) 编辑

C++多线程编程第七讲--单例设计模式共享数据分析,解决,call_once
摘要://(1)设计模式大概谈 // 使得程序灵活,但是代码阅读非常的晦涩。 //(2)单例设计模式 // 使用频率比较高。只能创建一个对象。 #include<iostream> using namespace std; class MyCAS { private: MyCAS() {}; //私有化构 阅读全文

posted @ 2021-10-17 11:46 xcxfury001 阅读(28) 评论(0) 推荐(0) 编辑

C++多线程编程第六讲--unique_lock详解
摘要://(1)unique_lock取代lock_guard,unique_lock是一个类模板,比lock_guard更加灵活。// lock_guard取代了mutex的lock()和unlock()。unique_lock比lock_guard效率低一点,内存占用多一些。 #include<ios 阅读全文

posted @ 2021-10-13 08:27 xcxfury001 阅读(391) 评论(0) 推荐(0) 编辑

C++多线程编程第五讲--互斥量概念、用法、死锁演示及解决详解
摘要://(1)互斥量的(mutex)的基本概念 // 就是一个类的对象。多个线程可以尝试对一个mutex的对象进行lock,但是只有一个线程成功,其他线程需要等待。 //(2)互斥量的用法 //(2.1)lock(), unlock():要成对使用 #include<iostream> #include 阅读全文

posted @ 2021-10-07 18:31 xcxfury001 阅读(76) 评论(0) 推荐(0) 编辑

C++多线程编程第四讲--创建多个线程、数据共享问题分析、案例代码
摘要://(1)创建和等待多个线程 #include<iostream> #include<thread> #include<vector> using namespace std; void myprint(int num) { cout << "this thread id = " << std::t 阅读全文

posted @ 2021-09-28 08:13 xcxfury001 阅读(66) 评论(0) 推荐(0) 编辑

C++多线程编程第三讲--线程传参详解,detach()大坑,成员函数做线程函数
摘要:/*线程传参详解,detach()大坑,成员函数做线程函数*/ //(1)传递临时对象作为线程参数 //(1.1)要避免的陷阱 #include<iostream> #include<thread> using namespace std; void myprint(const int& i, co 阅读全文

posted @ 2021-09-26 21:16 xcxfury001 阅读(170) 评论(0) 推荐(0) 编辑

C++多线程编程第二讲:线程启动、结束,创建线程多法,join,detach
摘要:/*线程启动、结束,创建线程多法,join,detach*/ //(1)线程运行的开始和结束 //主线程从main为入口。那我们自己创建的线程也需要从一个函数为入口。 // 当没有detach的时候,整个程序执行结束的标志是主线程执行结束。 //(1.1)thread #include<iostre 阅读全文

posted @ 2021-09-23 22:36 xcxfury001 阅读(139) 评论(0) 推荐(0) 编辑

C++多线程编程第一讲-并发的基本概念及实现,进程、线程基本概念
摘要:/*第一节 并发基本概念与实现,进程、线程基本概念*/ //(1)并发、进程、线程的基本概念和综述 //(1.1)并发:两个或者更多的任务同时进行,一个程序同时执行多个独立的任务。 // 单核cpu某一个时刻只能执行一个任务;单核cpu实行多任务的方式是进行任务切换实现的。 // 这是一种并发的假象 阅读全文

posted @ 2021-09-16 08:25 xcxfury001 阅读(67) 评论(0) 推荐(0) 编辑

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示