cocpp
0 人感兴趣 · 26 次引用
- 最新
- 推荐

一个 cpp 协程库的前世今生(二十六)共享栈
本文主要讲述了共享栈空间的协程切换细节,总体叙述比较粗,只是将原理大致串了一下。如果需要了解更多细节,建议参照源码。


一个 cpp 协程库的前世今生(二十四)对象池与栈内存池
本文介绍的cocpp中两种管理内存的方式,对象池与栈内存池,简要阐述了其实现原理。若想深入了解,可以参考源码。



一个 cpp 协程库的前世今生(二十一)协程重分配
本文介绍了当协程陷入系统调用,阻塞当前调度线程的时候,如何防止将同一个调度线程上其他的协程堵塞。这个手段是上一节中外部调度的一个良好补充。

一个 cpp 协程库的前世今生(二十)外部调度
本文讨论了从外部如何切换一个长时间运行的协程,并结合具体的代码案例来深入理解其机制,这一部分功能需要对内核信号处理的实现有一定的理解。在此基础上讨论了安全点存在的必要性以及其实现方法。

一个 cpp 协程库的前世今生(十九)event
回调函数在降低耦合的场景下很有用,但是其自身具有一定的局限性,扩展性不好。通过对它进行封装,我们既可以得到低耦合又可以得到扩展性。

一个 cpp 协程库的前世今生(十八)空闲与等待
本文介绍了协程休眠的原理,实际上是休眠调度线程,使用条件变量使调度线程让出CPU,避免空转。另外还介绍了进入睡眠的时机,唤醒的时机,以及哪些影响睡眠的操作,需要同步互斥量来保护。

一个 cpp 协程库的前世今生(十七)带时限的锁
本文介绍了前面三种互斥量对应的带时限的版本,总体来说就是利用一个模板类为现有的实现增加接口,衍生出功能更丰富的类,这个编程技巧在很多功能封装场景下都挺有用的。



一个 cpp 协程库的前世今生(十四)信号量与条件变量
本文介绍的条件变量与信号量的实现。其中条件变量其实就是std::condition_variable_any,并不关心底层的操作对象。而计数信号量是典型的生产者消费者写法,二值信号量是计数信号量的一个特例

一个 cpp 协程库的前世今生(十三)互斥量
本文讨论了互质量的实现方式,包括如何让协程在不消耗CPU的情况下去等待互斥量,如何解锁互斥量并唤醒对应的ctx。

一个 cpp 协程库的前世今生(十二)自旋锁
本文讲解了cocpp中自旋锁的实现,非常简单,可以说是简陋了。但是仅为其他同步工具提供底层支持也足够用了。

一个 cpp 协程库的前世今生(十一)等待与返回值
本文对如何获取协程的返回值做了介绍,分别介绍了不带超时的等待和带超时的等待,并且也介绍了如何处理无返回值函数的情况。

一个 cpp 协程库的前世今生(十)调度的流程
本文分析一个协程的整个生命周期从创建到销毁的主要流程,设计到大量代码实现,可以运行一下项目中的例子,使用调试器跟踪以加深理解。

一个 cpp 协程库的前世今生(九)协程参数与返回值的处理
本文从协程函数执行开始分析,自底向上分析了协程函数的每一次封装与转发,阐述了一个任意的函数怎样每协程框架调起来的。

一个 cpp 协程库的前世今生(八)env 的状态与标识位
本文介绍了cocpp调度中最重要的调度环境env的标识和状态的含义、设置条件等细节,代码贴的比较多,大致了解就可以了,后面还会经常遇到。

一个 cpp 协程库的前世今生(七)ctx 的状态与标识位
本文对ctx的标识与状态做了详尽的分析,包括各种标识的含义、设置与清除场景、用途,以及各种状态的关系,检测时机等内容。信心量较大,阅读时可参照源码,加深理解。

一个 cpp 协程库的前世今生(六)管理器 manager
本文介绍了cocpp框架三大基础组件中的最后一部分,希望读者朋友可以对整体架构有个认识,方便后面文章的理解。


一个 cpp 协程库的前世今生(四)协程上下文 ctx
本文对写成上下文中所有的字段进行了逐一介绍,对协程的状态转换进行了简要说明,对成员中可能会导致理解偏差的地方也做出了详细的解释。希望对后续章节的理解有所帮助。



一个 cpp 协程库的前世今生(一)缘起
我从大学知道有协程这么个东西之后就想自己写一个,所以并不是说现在开源的协程不满足我的需求,而是纯粹想体验一下从头开始设计开发会遇到什么困难,而我又能从中学到什么。 本文作为系列文章的第一篇,起一个引子的作用,希望自己可以坚持创作吧。