NAME
Chan_new, Chan_send, Chan_receive - synchronous communication primitives
SYNOPSIS
#include "chan.h"
typedef struct Chan_T *Chan_T;
Chan_T Chan_new(void);
size_t Chan_send(Chan_T c, void *ptr, size_t size);
size_t Chan_receive(Chan_T c, void *ptr, size_t size);
DESCRIPTION
These functions implement synchronous communication channels, which are semantically equivalent to the channels in Hoare's `Communicating Sequential Processes.' Channels are represented by opaque pointers of type Chan_T.
Chan_new
creates, initializes, and returns a new channel, which is a pointer. If the channel cannot be allocated, Chan_new returns NULL.
Chan_send
accepts a channel, a pointer a buffer that holds the data to be sent, and the number of bytes that buffer holds. The caller waits until another thread calls Chan_receive with the same channel; when this rendezvous occurs, the data is copied from the sender to the receiver and the calls return. Chan_send returns the number of bytes accepted by the receiver.
Chan_receive
accepts a channel, a pointer to a buffer that is to receive the data, and the maximum number of bytes that buffer can hold. The caller waits until another thread calls Chan_send with the same channel; when this rendezvous occurs, the data is copied from the sender to the receiver and the calls return. If the sender supplies more than size bytes, the excess bytes are discarded. Chan_receive returns the number of bytes accepted.
For both Chan_send and Chan_receive, size may be 0.
It is a checked runtime error to pass a NULL Chan_T to any function in this interface.
FILES
chan.h header file libthread.a library
SEE ALSO
sem(3), thread(3)
C. A. R. Hoare, `Communicating Sequential Processes,' CACM 21 8 (Aug. 1978), 666-677.