C 并發控制庫:MILL
MILL 為 C 語言提供了 Go 語言風格的并發控制。
示例代碼:
#include <stdio.h> #include <mill.h> void worker(int count, const char *text, chan ch) { int i; for(i = 0; i != count; ++i) { printf("%s\n", text); musleep(10000); } chs(ch, int, 0); chclose(ch); } int main() { chan ch1 = chmake(int, 0); go(worker(4, "a", chdup(ch1))); chan ch2 = chmake(int, 0); go(worker(2, "b", chdup(ch2))); choose { in(ch1, int, val): printf("coroutine 'a' have finished first!\n"); in(ch2, int, val): printf("coroutine 'b' have finished first!\n"); end } chclose(ch2); chclose(ch1); return 0; }
本文由用戶 fpcm 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!