摘要: 翻译来自:https://thispointer.com/c11-multithreading-part-10-packaged_task-example-and-tutorial/ 这一节我们将讨论 std::packaged_task std::packaged_task<>std::packa 阅读全文
posted @ 2021-11-08 19:41 冰糖葫芦很乖 阅读(71) 评论(0) 推荐(0) 编辑
摘要: 这节是讨论怎么使用std::async来执行异步task 什么是std::asyncstd::async()是一个接受回调(函数或函数对象)作为参数的函数模板,并有可能异步执行它们 template <class Fn, class... Args> future<typename result_o 阅读全文
posted @ 2021-11-08 19:32 冰糖葫芦很乖 阅读(60) 评论(0) 推荐(0) 编辑
摘要: 翻译来自:https://thispointer.com//c11-multithreading-part-8-stdfuture-stdpromise-and-returning-values-from-thread/ std::future对象可以和asych,std::packaged_tas 阅读全文
posted @ 2021-11-08 19:23 冰糖葫芦很乖 阅读(68) 评论(0) 推荐(0) 编辑
摘要: 翻译来自:https://thispointer.com//c11-multithreading-part-7-condition-variables-explained/ 条件变量是一种用于在2个线程之间进行信令的事件,一个线程可以等待它得到信号,其他的线程可以给它发信号。在c++11中,条件变量 阅读全文
posted @ 2021-11-08 19:04 冰糖葫芦很乖 阅读(91) 评论(0) 推荐(0) 编辑
摘要: 翻译来自:https://thispointer.com//c11-multithreading-part-6-need-of-event-handling/ 在这个文章中 我们将讨论多线程中事件处理的必要性 有时候 线程需要等待某件事情发生 比如条件为真或者是任务通过另外一个线程被完成了 比如 假 阅读全文
posted @ 2021-11-08 18:47 冰糖葫芦很乖 阅读(61) 评论(0) 推荐(0) 编辑
摘要: 翻译来自:https://thispointer.com//c11-multithreading-part-5-using-mutex-to-fix-race-conditions/ 在本文中,我们将讨论如何使用互斥锁来保护多线程环境中的共享数据并避免竞争条件。 为了修复多线程环境中的竞争条件,我们 阅读全文
posted @ 2021-11-08 18:35 冰糖葫芦很乖 阅读(55) 评论(0) 推荐(0) 编辑
摘要: 翻译来自:https://thispointer.com//c11-multithreading-part-4-data-sharing-and-race-conditions/ 在多线程环境中,线程之间的数据共享非常容易。但是这种简单的数据共享可能会导致应用程序出现问题。一个这样的问题是Race 阅读全文
posted @ 2021-11-08 18:25 冰糖葫芦很乖 阅读(71) 评论(0) 推荐(0) 编辑
摘要: 翻译来自:https://thispointer.com//c11-multithreading-part-3-carefully-pass-arguments-to-threads/ 要将参数传递给线程的可关联对象或函数,只需将参数传递给std::thread构造函数。 默认情况下,所有的参数都将 阅读全文
posted @ 2021-11-08 18:09 冰糖葫芦很乖 阅读(59) 评论(0) 推荐(0) 编辑
摘要: 学习网站:https://thispointer.com/c11-tutorial/ 阅读全文
posted @ 2021-11-08 17:51 冰糖葫芦很乖 阅读(64) 评论(0) 推荐(0) 编辑
摘要: 翻译来自https://thispointer.com//c11-multithreading-part-2-joining-and-detaching-threads/ Joining线程 线程一旦启动,另一个线程可以通过调用std::thread对象上调用join()函数等待这个线程执行完毕 s 阅读全文
posted @ 2021-11-08 17:41 冰糖葫芦很乖 阅读(124) 评论(0) 推荐(1) 编辑
摘要: 翻译来自:https://thispointer.com//c-11-multithreading-part-1-three-different-ways-to-create-threads/ 我们可以使用std::thread对象附加一个回调,当这个新线程启动时,它将被执行。 这些回调可以是,1、 阅读全文
posted @ 2021-11-08 17:20 冰糖葫芦很乖 阅读(110) 评论(0) 推荐(1) 编辑
摘要: async绑定类的成员函数 class myClass { public: bool test() { return true; } }; int main() { //myClass的一个实例 myClass obj; //利用std::bind绑定类的成员函数 auto func = std:: 阅读全文
posted @ 2021-11-08 11:16 冰糖葫芦很乖 阅读(509) 评论(0) 推荐(0) 编辑
摘要: 转载来自:https://www.cnblogs.com/taiyang-li/p/5914167.html #include <future> #include <iostream> bool is_prime(int x) { for (int i = 2; i < x; i++) { if ( 阅读全文
posted @ 2021-11-08 10:18 冰糖葫芦很乖 阅读(359) 评论(0) 推荐(0) 编辑