Go-style concurrency in C
Libmill is a library that introduces Go-style concurrency to C.
It can execute up to 20 million coroutines and 50 million context switches per second.
Go | C |
go foo(arg1, arg2, arg3) | go(foo(arg1, arg2, arg3)); |
ch := make(chan int) | chan ch = chmake(int, 0); |
ch := make(chan int, 1000) | chan ch = chmake(int, 1000); |
ch <- 42 | chs(ch, int, 42); |
i := <- ch | int i = chr(ch, int); |
close(ch) | chdone(ch, int, 0); |
<garbage collector> | chclose(ch); |
select { case ch <- 42: foo() case i := <- ch: bar(i) default: baz() } |
choose { out(ch, int, 42): foo(); in(ch, int, i): bar(i); otherwise: baz(); end } |
If you would prefer the same functionality with C-idiomatic API check libdill.
Libmill is licensed under MIT/X11 license.