Completed: Verified only for bounded channels (N > 1) in a single translation unit: finish sending, call end(), then drain in FIFO order to EOF. See the completion record. Pipelines remain experimental.
chan<T, N> is an experimental C++11 header for passing values between threads. The verified quick start uses a bounded channel (N > 1) in a single translation unit.
Get the source on Linux or WSL:
git clone https://github.com/ZisIsNotZis/cppChan.git
cd cppChanSave this as example.cpp next to chan.hpp:
#include "chan.hpp"
int main() {
chan<int, 3> channel; // Two usable slots.
channel << 17;
channel << 29;
channel.end();
int value;
if (!(channel >> value) || value != 17) return 1;
if (!(channel >> value) || value != 29) return 1;
return (channel >> value) ? 1 : 0; // EOF after draining.
}On Linux or WSL, compile and run it with a C++11 compiler:
c++ -std=c++11 -pthread example.cpp -o example && ./exampleOn success the program exits with status 0 and prints nothing: it checks 17, then 29, then EOF.
N - 1values fit in the buffer. A send waits for space if the buffer is full; a pull waits for a value if the buffer is empty and still open.- Call
end()after all producers have finished sending. Buffered values remain readable in FIFO order; a pull returnsfalseonce the closed buffer is empty. Do not rely on a send racing with or followingend()being delivered:operator<<cannot report whether it sent a value. - The channel default-constructs its slots. Sending an lvalue uses copy assignment; sending an rvalue and pulling into an existing object use assignment from an rvalue (normally move assignment). After a successful rvalue send, treat the source as moved-from according to
T's assignment semantics; it does not receive the old slot value. A pull assigns into the destination instead of swapping with it; the destination must meetT's own assignment requirements.
Run bash tests/run-bounded-close.sh on Linux or WSL for the deadline-bounded checks. See the test notes for coverage and baseline results. The suite checks same-thread FIFO and close/drain, plus a one-producer/one-consumer handoff. It does not establish general multi-producer/multi-consumer behavior, wake-up of a waiter known to be blocked, or multi-translation-unit linking.
The zero-capacity specialization (chan<T, 0>) and pipeline helpers (pipE and pipe) are experimental and are not covered by the example, the bounded close contract, or the tests above.
For reproducible bounded-channel problems, use GitHub Issues and include the commit, compiler, and failing case. No license is specified in this repository; do not assume permission to redistribute or integrate the header.