- 基于*nix的
<ucontext.h>
实现 - 参考云风的coroutine实现
- 支持linux、unix、Mac OS X
- 协程库实现相关文章可以参考从ucontext到coroutine
- 提供对等协程实现
- hook进一些systemcall,将所有fd设为非阻塞,并在epoll中切换协程,实现用户侧阻塞IO,实现侧非阻塞效率。
$ make
$ bin/test
控制台应当打印:
main start
coroutine 0 : 0
coroutine 1 : 200
coroutine 0 : 1
coroutine 1 : 201
coroutine 0 : 2
coroutine 1 : 202
coroutine 0 : 3
coroutine 1 : 203
coroutine 0 : 4
coroutine 1 : 204
main end
简单的性能测试可以:
$ bin/test-perform
在Ubuntu 16.04LTS, i7-5500U 3GB(VMWARE虚拟机)测试结果为:
switch times test start!
switch times test end!
It can switch 879039.736991 times