Effective Modern C++ 笔记 第七章 The Concurrency API

Item 35: Prefer task-based programming to thread-based. 241
Item 36: Specify std::launch::async if asynchronicity is essential. 245
Item 37: Make std::threads unjoinable on all paths. 250
Item 38: Be aware of varying thread handle destructor behavior. 258
Item 39: Consider void futures for one-shot event communication. 262

Item 40: Use std::atomic for concurrency, volatile for special memory.


这章开始讲STL了,理解起来比core language简单,需要的经验值比core language更高。。。讲core language尚可以像教科书般的细细研读,讲STL的话,基本就是看得懂,不知道为什么,看完就忘。。。


从std::thread线程语义进化到std::async的task语义,使用起来更方便,然后就是坑又多了几个,比如关于std::async的policy,比如关于std::future其实我有shared state等等。然后顺便提了std::thread的坑:如果thread是joinable的,那么std::thread的dtor直接结束程序。所以在dtor之前,一定要留意吧程序的thread对象都置为unjoinable。


Item39介绍了一种通过future,promise来替代mutex,cond_var组合的通知形式,不过只适用于事件被通知一次的情况。而mutex,cond_var组合是可以通知多次的。被pthread_mutex, pthread_cond 虐过的看个条款很轻松。


Item40介绍了atomic和很苦逼的volatile关键字。atomic印象最深的就是copy ctor和operator=是被delete的。这个Item的扩展可以看下Herb Sutter的视频: C++ Atomic Weapons,channel9有下



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值