Libdill是一个C开发库,可以轻松用来编写结构化的并发程序。下面例子启动两个并发的worker函数打印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
评论