C 语言的 Channels chan
9月13日#成都#源创会,Swift、Docker、云计算、大数据!
chan 是纯 C 实现的 Go 的 Channels,示例代码:
#include <pthread.h>#include <stdio.h>#include "chan.h"chan_t* chan;void* ping(){ // Send blocks until receiver is ready. chan_send(chan, "ping"); return NULL;}int main(){ // Initialize unbuffered channel. chan = chan_init(0); pthread_t th; pthread_create(&th, NULL, ping, NULL); // Receive blocks until sender is ready. void* msg; chan_recv(chan, &msg); printf("%s\n", msg); // Clean up channel. chan_dispose(chan);}