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.
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有下