2016-12-03 ruki
tbox provides a lightweight implementation of stackless coroutines and it's interfaces are very simple too, for example: c tb_lo_coroutine_enter(coroutine) { while (1) { tb_lo_coroutine_yield(); } } The switch performance of this stackless coroutines is faster than the implementation of tbox's 继续阅读 »
2016-04-02 Xie Jingyi
写在前面 本文默认读者对 Python 生成器 有一定的了解,不了解者请移步至生成器 - 廖雪峰的官方网站。 本文基于 Python 3.5.1,文中所有的例子都可在 Github 上获得。 学过 Python 的都知道,Python 里有一个很厉害的概念叫做 生成器(Generators)。一个生成器就像是一个微小的线程,可以随处暂停,也可以随时恢复执行,还可以和代码块外部进行数据交换。恰当使用生成器,可以极大地简化代码逻辑。 也许,你可以熟练地使用生成器完成一些看似不可能的任务,如“无穷斐波那契数列”,并引以为豪,认为所谓的生成器也不过如此——那我可要告诉你:这些都太小儿科了,下面我所要介绍的绝对会让你大开眼界。 生成器 继续阅读 »
2016-10-28 ruki
Introduction Benchbox is a benchmark testing utilities based on xmake and tbox. Build Please install xmake first: xmake bash $ xmake The Coroutine Switch Reports (2 Coroutines) Run bash $ xmake coroutine -n switch Macosx (x86_64) tbox: 10000000 switches in 205 ms, 48780487 switches per sec 继续阅读 »
2015-11-06 Li Shuai
协程是用户态内的,或者准确点说是线程内部的一种上下文切换技术,由于协程切换是在用户态下完成的,所以省去了线程切换时频繁出入内核态的资源开销,可以形成一种很高效的协作式并发技术。 这个简短的视频介绍了一些有关协程、并发之类的东西,很有意义。 Coroutines, event loops, and the history of Python generators 从里面学习到两种很好的协程的调度方式。把代码拿过来分享一下。 Coroutine trampoline 这种方式下的协程调度比较好理解,就是从一个初始状态开始,一条执行线索不断的在多个协程之间切换,就好像多个协程协作完成一项任务。 代码: def co_tramp 继续阅读 »