浅墨浓香

想要天亮进城,就得天黑赶路。
随笔 - 743, 文章 - 16, 评论 - 87, 阅读 - 53万

导航

< 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

10 2019 档案

摘要:一. “共享状态” (一)“共享状态”对象 1. 用于保存线程函数及其参数、返回值以及新线程状态等信息。该对象通常创建在堆上,由std::async、std::promise和std::package_task等提供(Provider),并交由future/shared_future管理。 2. P 阅读全文

posted @ 2019-10-26 16:05 浅墨浓香 阅读(1621) 评论(0) 推荐(0) 编辑

摘要:一. std::async函数模板 (一)std::async和std::thread的区别 1. 两者最明显的区别在于async采用默认启动策略时并不一定创建新的线程。如果系统资源紧张,那么std::thread创建线程可能失败,系统报告异常,整个程序可能崩溃。而std::async一般则不会,它 阅读全文

posted @ 2019-10-23 17:41 浅墨浓香 阅读(3004) 评论(0) 推荐(1) 编辑

摘要:一. 线程的等待与分离 (一)join和detach函数 1. 线程等待:join() (1)等待子线程结束,调用线程处于阻塞模式。 (2)join()执行完成之后,底层线程id被设置为0,即joinable()变为false。同时会清理线程相关的存储部分, 这样 std::thread 对象将不再 阅读全文

posted @ 2019-10-12 10:34 浅墨浓香 阅读(6864) 评论(0) 推荐(1) 编辑

摘要:一. std::thread类 (一)thread类摘要及分析 class thread { // class for observing and managing threads public: class id; using native_handle_type = void*; thread( 阅读全文

posted @ 2019-10-08 09:33 浅墨浓香 阅读(12384) 评论(0) 推荐(0) 编辑

摘要:一. make系列函数 (一)三个make函数 1. std::make_shared:用于创建shared_ptr。GCC编译器中,其内部是通过调用std::allocate_shared来实现的。 2. std::make_unique:C++14中加入标准库。 3. std::allocate 阅读全文

posted @ 2019-10-05 20:24 浅墨浓香 阅读(1056) 评论(0) 推荐(0) 编辑

摘要:一. weak_ptr的概况 (一)weak_ptr的创建 1. 直接初始化:weak_ptr<T> wp(sp); //其中sp为shared_ptr类型 2. 赋值: wp1 = sp; //其中sp为shared_ptr类型 wp2 = wp1; //其中wp1为weak_ptr类型 (二)常 阅读全文

posted @ 2019-10-05 00:11 浅墨浓香 阅读(2965) 评论(0) 推荐(1) 编辑

摘要:一. shared_ptr的基本用法 (一)与unique_ptr的比较 比较 shared_ptr unique_ptr 备注 初始化 ①shared_ptr<T> sp; sp.reset(new T()); ②shared_ptr<T> sp(new T()); ③shared_ptr<T> 阅读全文

posted @ 2019-10-04 16:19 浅墨浓香 阅读(2401) 评论(0) 推荐(0) 编辑

摘要:一. unique_ptr的基本用法 (一)初始化方式 1. 直接初始化:unique<T> myPtr(new T); //ok。但不能通过隐式转换来构造,如unique<T> myPtr = new T()。因为unique_ptr构造函数被声明为explicit。 2. 移动构造:unique 阅读全文

posted @ 2019-10-03 11:09 浅墨浓香 阅读(4019) 评论(0) 推荐(2) 编辑

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