chanfd is a tiny C library that implements channels for inter-thread/process
communication. These channels are similar to the channels in Plan9's
libthread or
Go. chanfd, however, does not support co-routines.
Not quite. chanfd has a much narrower goal: it doesn't provide co-routines
(it works with regular threads/processes), does not take over your main(),
knows nothing about networking, and does not do any macro trickery to make
C look like something else.
chanfd is basically a simple wrapper around Linux' eventfd(2), which
means you can use standard polling calls such as select(2) or epoll(2)
to wait on channels just like on any other file descriptors.
struct chanfd *chanfd_create(size_t size, size_t n_elems); /* pass size=0 for unbuffered channel */
void chanfd_destroy(struct chanfd *); /* Note: no 'close' operation */
void chanfd_recv(struct chanfd *chan, void *data); /* see the header file for type-safe macros */
void chanfd_send(struct chanfd *chan, const void *data);
int chanfd_receiver_fd(struct chanfd *chan); /* these can be used with select(2) etc. */
int chanfd_sender_fd(struct chanfd *chan);
bool chanfd_is_empty(struct chanfd *chan);chanfd_send and chanfd_recv are expensive; they issue syscalls that take at
least one lock. However, chanfd_is_empty is fast and scalable since it only
needs a SMP load fence and a load.
- Linux >= v2.6.30
- Concurrency Kit. Run
./configure --helpfor options regarding Concurrency Kit's installation.
Bell Labs and CSP Threads by Russ Cox.
- chan
- eb_chan
- libmill
- libtask
- Plan9's libthread
- or just use the Go Programming Language
Simplified BSD License -- see LICENSE.