Go-style channels in C.
This project respects Golang channels and rewrites it in C based on C99 standard. The implementation is just quite simple, no fancy features included.
The following C code creates an unbuffered channel (buffered if size is specified), then pushes a string hello to the channel:
struct chan * ch = chan_make(sizeof(char *), 0);
// sender
char * str = strdup("hello");
chan_send(ch, &str);
// receiver
char * str;
chan_recv(ch, &str);
free(str);Equivalent Go code:
ch := make(chan string)
// sender
ch <- "hello"
// receiver
<- chLet's say you don't want overhead on data transmission but a sychronization way:
struct chan * ch = chan_make(0, 0);
chan_send(ch, NULL);Equivalent Go code:
ch := make(chan struct{})
ch <- struct{}{}