• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
我是张洪铭我是熊博士
时光静好,与君同;细水长流,与君语
博客园    首页    新随笔    联系   管理    订阅  订阅
10 2021 档案
std::get<C++11多线程库~线程间共享数据>(10):使用互斥量保护共享数据(5)

摘要:1 /* 2 * 话题1:使用互斥量保护共享数据 3 * 4 * 接下来学习第五个小话题:避免死锁的进阶指导 5 * 6 * 这一小节的内容,完全引用,只在最后补充上我对这部分的理解,以及更多一点的想法 7 */!!! 非常有意思的是下面讲到的 “使用锁的层次结构”。 锁的层次的意义在于提供对运行时 阅读全文
posted @ 2021-10-30 21:13 我是张洪铭我是熊博士 阅读(147) 评论(0) 推荐(0)
std::get<C++11多线程库~线程间共享数据>(10):使用互斥量保护共享数据(4)

摘要:1 #ifndef DEADLOCK_QUESTIONDESCRIBLE_AND_SOLUTION_H 2 #define DEADLOCK_QUESTIONDESCRIBLE_AND_SOLUTION_H 3 4 /* 5 * 话题1:使用互斥量保护共享数据 6 * 7 * 接下来学习第四个小话题 阅读全文
posted @ 2021-10-29 22:35 我是张洪铭我是熊博士 阅读(50) 评论(0) 推荐(0)
C++多线程库的常用函数 std::lock()

摘要:格式:函数名 + 头文件 + 用例 + 解释说明 1 函数名: 2 std::lock() 3 4 头文件: 5 #include <mutex> 6 7 用例: 8 std::mutex ma, mb, mc; 9 std::lock(ma, mb, mc); 10 std::lock_guard 阅读全文
posted @ 2021-10-28 21:53 我是张洪铭我是熊博士 阅读(1021) 评论(0) 推荐(1)
std::get<C++11多线程库~线程间共享数据>(10):使用互斥量保护共享数据(3)

摘要:1 #ifndef LOCATE_INTERFACES_RACE_CONDITION 2 #define LOCATE_INTERFACES_RACE_CONDITION 3 4 /* 5 * 话题1:使用互斥量保护共享数据 6 * 7 * 接下来学习第三个小话题:定位接口间的条件竞争 8 * 9 阅读全文
posted @ 2021-10-28 20:18 我是张洪铭我是熊博士 阅读(84) 评论(0) 推荐(0)
std::get<C++11多线程库~线程间共享数据>(10):使用互斥量保护共享数据(2)

摘要:1 #ifndef USE_CODE_PROTECTED_DATA_H 2 #define USE_CODE_PROTECTED_DATA_H 3 4 /* 5 * 话题1:使用互斥量保护共享数据 6 * 7 * 接下来学习第二个小话题:用代码来保护共享数据 8 * 9 * 从第一个小话题可以看到, 阅读全文
posted @ 2021-10-28 20:14 我是张洪铭我是熊博士 阅读(51) 评论(0) 推荐(0)
std::get<C++11多线程库~线程间共享数据>(10):使用互斥量保护共享数据(1)

摘要:1 /* 2 * 话题1:使用互斥量保护共享数据 3 * 4 * 1. C++中使用互斥量 5 * 2. 用代码来保护共享数据 6 * 3. 定位接口间的条件竞争 7 * 4. 死锁:问题描述及解决方案 8 * 5. 避免思索的进阶指导 9 * 6. std::unique_lock 灵活的锁 10 阅读全文
posted @ 2021-10-22 12:04 我是张洪铭我是熊博士 阅读(64) 评论(0) 推荐(0)
C++多线程库的常用模板类 std::lock_guard

摘要:格式:类名 + 头文件 + 用例 + 解释说明 1 模板类类名: 2 std::lock_guard 3 4 头文件: 5 #include <mutex> 6 7 用例: 8 9 std::mutex m; 10 std::lock_guard<std::mutex> lk(m); 解释说明: C 阅读全文
posted @ 2021-10-22 11:32 我是张洪铭我是熊博士 阅读(912) 评论(0) 推荐(0)
C++多线程库的常用类 std::mutex

摘要:格式:类名 + 头文件 + 用例 + 解释说明 1 类名: mutex 2 3 头文件: #include <mutex> 4 5 用例; 6 std::mutex m_mutex; 解释说明: std::mutex C++提供的互斥量,用在多线程编程中,来保护共享数据。 C++中通过实例化std: 阅读全文
posted @ 2021-10-22 11:28 我是张洪铭我是熊博士 阅读(489) 评论(0) 推荐(0)
std::get<C++11多线程库~线程间共享数据>(09):共享数据带来的问题(1)

摘要:1 #include <QCoreApplication> 2 3 /* 4 * 话题1:线程间共享数据 5 * a. 共享数据带来的问题 6 * b. 使用互斥量保护数据 7 * c. 数据保护的替代方案 8 * 9 * 多个线程只读的访问某一个相同的数据,不会出现问题; 10 * 多个线程有读有 阅读全文
posted @ 2021-10-08 21:35 我是张洪铭我是熊博士 阅读(89) 评论(0) 推荐(0)
C++多线程库的常用函数 std::this_thread::get_id()

摘要:格式:函数 + 头文件 + 用例 + 解释说明 函数: std::this_thread::get_id() 头文件: <thread> 用例: std::thread::id master_thread = std::this_thread::get_id(); 另一种获取线程标识符 id 的办法 阅读全文
posted @ 2021-10-08 20:19 我是张洪铭我是熊博士 阅读(7725) 评论(0) 推荐(0)
C++多线程库的常用函数积累和整理

摘要:std::this_thread::get_id() 获取线程标识符 std::thread::hardware_concurrenc() 获取硬件能够支持的一个应用程序最对的线程数量 C++多线程库的常用类 std::mutex C++提供的互斥量,用在多线程编程中,来保护共享数据。 C++多线程 阅读全文
posted @ 2021-10-08 20:15 我是张洪铭我是熊博士 阅读(252) 评论(0) 推荐(0)
STL 算法 std::for_each

摘要:std::for_each(threads.begin(),threads.end(), std::mem_fn(&std::thread::join)); 1. 说明 2. 写用法 3.写样例 直接参考 cplusplus官网讲解: http://www.cplusplus.com/referen 阅读全文
posted @ 2021-10-04 16:38 我是张洪铭我是熊博士 阅读(3489) 评论(0) 推荐(0)
STL 算法清单

摘要:C++/Reference/Other/functional/ STL 算法 std::mem_fn 成员函数转为函数对象 C++/Reference/Other/algorithm/ STL 算法 std::for_each 遍历一段区间内的元素,并把元素作为参数,执行一个可调用对象 C++/Re 阅读全文
posted @ 2021-10-04 15:12 我是张洪铭我是熊博士 阅读(62) 评论(0) 推荐(0)
std::get<C++11多线程库~线程管理>(09):运行时决定线程数量

摘要:1 #include <QCoreApplication> 2 #include <thread> 3 #include <iostream> 4 #include <algorithm> 5 #include <vector> 6 7 /* 8 * 话题1: 运行时决定线程的数量。 9 * 线程的 阅读全文
posted @ 2021-10-04 15:09 我是张洪铭我是熊博士 阅读(147) 评论(0) 推荐(0)
C++多线程库的常用函数 std::thread::hardware_concurrency()

摘要:格式:函数 + 头文件 + 用例 + 解释说明 1. 函数 std::thread::hardware_concurrency() 头文件 #include <thread> 用例 unsigned long const hardware_threads = std::thread::hardwar 阅读全文
posted @ 2021-10-04 14:29 我是张洪铭我是熊博士 阅读(1750) 评论(0) 推荐(0)
STL 算法 std::mem_fn

摘要:std::for_each(threads.begin(),threads.end(), std::mem_fn(&std::thread::join)); 1. 说明 2. 写用法 3.写样例 直接参考 cplusplus官网讲解:http://www.cplusplus.com/referenc 阅读全文
posted @ 2021-10-03 17:49 我是张洪铭我是熊博士 阅读(682) 评论(0) 推荐(0)
STL 算法 std::advance

摘要:std::advance(block_end,block_size); 1. 写说明 2. 写用法 3.写样例 直接参考 cplusplus官网讲解:http://www.cplusplus.com/reference/iterator/advance/ 我的理解: std::advance 第一个 阅读全文
posted @ 2021-10-03 17:45 我是张洪铭我是熊博士 阅读(3121) 评论(0) 推荐(0)
STL 算法 std::min

摘要:1 unsigned long const num_threads= 2 std::min(hardware_threads != 0 ? hardware_threads : 2, max_threads); 1. 写说明 2. 写用法 3.写样例 未完,待续.... 阅读全文
posted @ 2021-10-03 17:40 我是张洪铭我是熊博士 阅读(230) 评论(0) 推荐(0)
STL 算法 std::distance

摘要:unsigned long const length=std::distance(first,last); 1. 写说明 2. 写用法 3.写样例 未完,待续.... 阅读全文
posted @ 2021-10-03 17:36 我是张洪铭我是熊博士 阅读(459) 评论(0) 推荐(0)
STL 算法 std::accumulate

摘要:1. 写说明 2. 写用法 3.写样例 未完,待续.... 阅读全文
posted @ 2021-10-03 17:35 我是张洪铭我是熊博士 阅读(67) 评论(0) 推荐(0)
std::get<C++11多线程库~线程管理>(08):转移线程所有权(2)

摘要:1 /* 2 * 话题1:基于“转移线程的所有权”,改进 thread_guard 类, 确保 std::thread 可以被 join或detach。 3 * 类 Scoped_thread 的构造函数把参数传递的 std::thread 拥有的所有权转移到自身成员变量上。 4 * 如果参数传递的 阅读全文
posted @ 2021-10-01 11:32 我是张洪铭我是熊博士 阅读(111) 评论(0) 推荐(0)
std::get<C++11多线程库~线程管理>(08):转移线程所有权(1)

摘要:1 #include <QCoreApplication> 2 #include <thread> 3 #include <iostream> 4 5 /* 6 * 话题1:转移线程的所有权。 7 * std::thread 构造函数需传入一个函数或可调用对象, 每一个 std::thread 都关 阅读全文
posted @ 2021-10-01 10:48 我是张洪铭我是熊博士 阅读(102) 评论(0) 推荐(0)

博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3