[分享] Fiber(Coroutine)

看板C_and_CPP作者 (艾斯寇德)時間15年前 (2009/05/11 01:45), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
在上次分享過Coroutine後, 在這裡分享當初所提到的類似Fiber的Coroutine 以下是下載點 http://sunneo.myweb.hinet.net/public/CFiber.zip 包裝內的SrcRelease為主要的source以及header 在包裝外的是Code::Blocks 8.0.3 以及Bloodshed DevC++ 4.9.9.2 的專案檔 有double fiber以及fibonacci sequence generator的測試 fibonacci測試可以當成是打斷連續執行函式,使用暫時結果的一個範例。 ========================================================================= 這是一種需要配置stack size的做法,這跟WinAPI的Fiber很像,主要做法是 jmpbuf.eip = runner jmpbuf.ebp = heap allocation 在啟動時longjmp(jmpbuf) 這時候會因為jmpbuf的設定,使得位址跑到runner 且堆疊的起始位置成為heap。 因此可以預留相當大的空間。 為了跟大多數的coroutine一樣可以有個參數,所以由runner叫用Fiber所給定的 函式並傳參數。 這程式的做法是來自於Portable Coroutine Library (pcl) 只是他原先撰寫的pcl部分將MinGW/MSVC的jmp_buf列為不支援。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.39.205.228
文章代碼(AID): #1A1nAz44 (C_and_CPP)