摘要: 点击查看代码 #include <iostream> #include <future> using namespace std; int func() { int i = 0; for (i = 0; i < 10; i++) { i++; } return i; } // 异步任务 void f 阅读全文
posted @ 2025-06-18 20:11 chen0508 阅读(30) 评论(0) 推荐(0)
摘要: 点击查看代码 #include <iostream> #include <thread> #include <mutex> #include <string> #include <condition_variable> #include <queue> std::queue<int> g_queue 阅读全文
posted @ 2025-06-17 15:52 chen0508 阅读(15) 评论(0) 推荐(0)
摘要: 为了确保单个类同一时间内只被调用一次,使用call_once()函数单例模式。 点击查看代码 #include <iostream> #include <thread> #include <mutex> #include <string> class Log { public: Log() {}; 阅读全文
posted @ 2025-06-17 11:36 chen0508 阅读(30) 评论(0) 推荐(0)
摘要: 以下内容是对b站陈子青视频课程做的笔记(感谢deepseek提供的帮助) 4.互斥量死锁问题(略) 5.lock_guard和unique_lock std::lock_guard 1)调用构造函数自动加锁,调用析构函数自动解锁。 2)lock_guard不可复制和移动 std::unique_lo 阅读全文
posted @ 2025-06-17 10:09 chen0508 阅读(55) 评论(0) 推荐(0)
摘要: 本节是学习b站程序员陈子青线程池项目知识点笔记。 一、C++线程库的基本使用 1.创建线程 需要一个可调用的函数或函数对象,作为线程的入口点,基本语法如下: 点击查看代码 #include <thread> //头文件 std::thread t(function_name, args...); / 阅读全文
posted @ 2025-06-16 17:19 chen0508 阅读(84) 评论(0) 推荐(0)
摘要: 1.Spaces in Template Expression C++11能更加智能的识别vector中没有空格的情况 2.nullptr和std::nullptr nullptr是一个代表空指针常量的关键字,明确表达“空指针"的意图,更加易读易用。 std::nullptr_t是nullptr的" 阅读全文
posted @ 2025-06-12 21:31 chen0508 阅读(21) 评论(0) 推荐(0)
摘要: 事先声明,此文是本人基于巩固学习成果所作的笔记,部分内容虽然基础,由于本人不熟悉,仍然作了解释,故常有繁冗之处,有错误之处欢迎大佬提出批评。 Variadic Template(可变参数模板)是C++11中极为重要的一个知识点,也是课程中第一个讲的知识点,下面是课程中的示例代码: 点击查看代码 te 阅读全文
posted @ 2025-06-12 11:02 chen0508 阅读(36) 评论(0) 推荐(0)