04 2018 档案
C++ coroutine-ts 怎么用-Part 3 从generator看co_yield怎么用
摘要:clang和MSVC的最新实现已经提供了试验性的协程实现,想要试用的话,clang需要开启-fcoroutins-ts -stdlib=libc++两个开关,而MSVC需要开启/await开关。 我们从一个简单的generator来看编译器做了什么: #include #include namespace stdexp = std::experimental;stdexp::generator... 阅读全文
posted @ 2018-04-18 21:17 PointerSMQ 阅读(787) 评论(0) 推荐(0)
C++ coroutine-ts 怎么用-Part 2 coroutine有什么用
摘要:上一篇说了coroutine的本质是什么,就是resumable function,那么一个函数有了suspend和resume功能之后,会打开什么样的新世界大门呢?随便举几个例子。 函数每次被唤醒,就丢出一个值,然后暂停——这是generator 函数启动一个IO操作,注册IO操作完成时唤醒自己,然后暂停——这是async-await 函数开启一个管道,暂停,另一个函数往管道... 阅读全文
posted @ 2018-04-12 17:34 PointerSMQ 阅读(593) 评论(2) 推荐(2)
C++ coroutine-ts 怎么用-Part 1 什么是coroutine
摘要:什么是coroutine 什么是coroutine?接触过的脑子里肯定会蹦出来很多词:async-await,generator,channel,yield,高并发,甚至goroutine。其实,这些都是coroutine的外部表象,coroutine的本质是什么?上古时期的计算机科学家们早就给出了概念,coroutine就是可以中断并恢复执行的subroutine,什么是subroutin... 阅读全文
posted @ 2018-04-10 17:38 PointerSMQ 阅读(1152) 评论(2) 推荐(0)
三张图解释为什么 std::shared_ptr 需要保存 weak_count
摘要:更正:图里面的shared_core在实现里面一般叫ref_count_base,是一个多态的东西 阅读全文
posted @ 2018-04-05 13:04 PointerSMQ 阅读(723) 评论(0) 推荐(0)