c/c++ coroutine

1.實現機制

1.1. switch-case
Protothread
最輕,但受限最大

1.2. setjmp/longjmp
StateThread採用這種方式

1.3. ucontext

1.4. boost::context

針對不同的arch用匯編實現的

http://www.boost.org/doc/libs/1_59_0/libs/context/doc/html/index.html

2.C的coroutine庫

Cgreenlet
coroutine
boost.coroutine
Protothreads
orchid
Statethread
Libco
coroutine_event
libconcurrency
setjmp-longjmp-ucontext-snippets
libcilkrts
libgo
libtask

3.cgreenlet

https://github.com/geertj/cgreenlet
cross-platfrm coroutine library for C/C++

cgreenlet introduce
https://github.com/geertj/cgreenlet/blob/master/doc/intro.txt

4.coroutine
https://github.com/cloudwu/coroutine/

5.protothread
http://dunkels.com/adam/pt/

6.coroutine_event
coroutine_event –它基於libevent,提供了基於協程的併發模型
在libevent的基礎上提供同步的接口,在獲得異步效率的同時提供更方便的編程方式
https://github.com/colaghost/coroutine_event

7.orchid

https://github.com/ioriiod0/orchid
orchid是一個構建於boost庫基礎上的C++庫,爲用戶提供基於協程的併發模型

8.Libco

libco是一個有趣的協程基礎庫,僅有的幾個函數接口 co_create/co_resume/co_yield 再配合 co_poll,可以支持同步或者異步的寫法,如線程庫一樣輕鬆,庫裏面提供了socket族函數的hook,使得後臺邏輯服務幾乎不用修改邏輯代碼就可以完成異步化改造。

http://code.tencent.com/libco.html
https://code.csdn.net/Tencent/libco

9.Statethread

The State Threads Library is a small application library which provides a foundation for writing fast and highly scalable Internet applications (such as web servers, proxy servers, mail transfer agents, and so on, really any network-data-driven application) on UNIX-like platforms. It combines the simplicity of the multithreaded programming paradigm, in which one thread supports each simultaneous connection, with the performance and scalability of an event-driven state machine architecture. In other words, this library offers a threading API for structuring an Internet application as a state machine.

http://state-threads.sourceforge.net/
http://sourceforge.net/projects/state-threads/

10.libconcurrency
https://code.google.com/p/libconcurrency/

11.setjmp-longjmp-ucontext-snippets
https://github.com/danluu/setjmp-longjmp-ucontext-snippets

12.libtask
http://swtch.com/libtask/

發佈了32 篇原創文章 · 獲贊 13 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章