LibdillC 語言并發(fā)編程庫
Libdill 是一個 C 開發(fā)庫,可以輕松用來編寫結(jié)構(gòu)化的并發(fā)程序。下面例子啟動兩個并發(fā)的 worker 函數(shù)打印 Hello 和 World :
#include <libdill.h>
#include <stdio.h>
#include <stdlib.h>
coroutine void worker(const char *text) {
while(1) {
printf("%s\n", text);
msleep(now() + random() % 500);
}
}
int main() {
go(worker("Hello!"));
go(worker("World!"));
msleep(now() + 5000);
return 0;
}
編譯方法:
$ cc -ldill -o hello hello.c
評論
圖片
表情
