Go-style channels and select for C++. Threads exchange values through Channel<T>, and Select_Any waits on several channels at once — without you writing a single std::mutex or std::condition_variable by hand.
#include <thread>
//
#include <sluice/sluice.hpp>
Sluice::Channel<int> numbers(4); // buffered, capacity 4
std::thread producer([&] {
for (int i = 1; i <= 10; ++i)
numbers.Send_Value(i);
});
int value = numbers.Receive_Value(); // blocks until something arrivesC++ has never had a mature, actively maintained library offering real multi-threaded channels with a working select — existing attempts are either single-threaded by design or abandoned. Sluice fills that gap: real multi-thread channels, a select that waits on multiple channels without busy-waiting, and an API that stays out of your way.
Channel<T>— capacity0is a true rendezvous (Send_Valueblocks until another thread actually receives the value); capacityN > 0is a bounded buffer. Blocking (Send_Value/Receive_Value) and non-blocking (Try_Receive) APIs,Close()with correct draining semantics, thread-safe with any number of producers and consumers on the same channel.Select_Any— waits on 2 or 3 channels at once, returns as soon as any one of them has data, without busy-waiting. Generalizing this to an arbitrary number of channels is planned but not implemented yet.- C++14 and up — the same headers adapt automatically to whatever standard your project targets, using more modern standard library features where the compiler supports them and falling back to equivalent code where it doesn't. You don't need to match any specific standard; whatever C++14-or-newer version you already use is enough.
Tonly needs to be move-constructible. No copy requirement anywhere.
Send_Valueon an already-closed channel throwsstd::logic_errorimmediately.Receive_Valuethrows only once a channel is both closed and empty — buffered values sent beforeClose()are still delivered normally.Try_Receivenever throws; it just returns an empty result when there's nothing to receive.- On a rendezvous channel (capacity
0), ifClose()happens after a value was handed toSend_Valuebut before a receiver actually took it,Send_Valuethrows too — the value stays enqueued (still receivable by whoever looks), but the sender is told the handoff itself didn't happen. Select_Anythrows if every channel passed to it is closed and empty at the same time, since none of them could ever produce a value again. It keeps waiting normally as long as at least one channel is still open.
- A C++14-or-newer compiler.
- CMake 3.25+.
cmake -S . -B build
cmake --build buildThis builds a static library (libsluice.a / sluice.lib) by default, plus the examples and tests. Useful options:
| Option | Default | Effect |
|---|---|---|
SLUICE_BUILD_SHARED |
OFF |
Build a shared library (.so/.dll) instead of static. |
SLUICE_BUILD_EXAMPLES |
ON |
Build the programs under examples/. |
SLUICE_BUILD_TESTS |
ON |
Build the test suite and register it with CTest. |
Run the tests with ctest --test-dir build after building.
Vendored via add_subdirectory or FetchContent:
add_subdirectory(sluicecpp)
target_link_libraries(your_target PRIVATE Sluice::sluice)Or after installing (cmake --install build):
find_package(Sluice 1.0 REQUIRED)
target_link_libraries(your_target PRIVATE Sluice::sluice)Both forms give you the same Sluice::sluice target, so switching between them later doesn't require changing anything else in your build.
If you're linking against the shared library directly (not through CMake), define SLUICE_SHARED when compiling your own code — CMake consumers get this automatically.
Copyright © 2026 Calasans
This software is licensed under the terms of the Apache License, Version 2.0 ("License"); you may not use this software except in compliance with the License. A copy of the License can be obtained at: http://www.apache.org/licenses/LICENSE-2.0
The present license grants, free of charge, to any person obtaining a copy of this software and associated documentation files, the following rights:
- Use, copy, modify, and distribute the software in any medium or format, for any purpose, commercial or non-commercial
- Merge, publish, distribute, sublicense, and/or sell copies of the software
- Permit persons to whom the software is furnished to do the same
All distributions of the software or derivative works must:
- Include a complete copy of this license
- Clearly indicate any modifications made to the original source code
- Preserve all copyright, patent, trademark, and attribution notices
- Provide adequate documentation of implemented changes
- Maintain the license and warranty notice in all copies
- This license does not grant permission to use trademarks, logos, or trade names of Calasans
- Contributions to the source code must be licensed under the same terms as this license
- The use of contributor names to endorse or promote products derived from this software requires specific prior permission
The software and all associated documentation are protected by copyright laws and international treaties. Calasans retains all rights, titles, and interests not expressly granted by this license.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
For detailed information about the Apache License 2.0, see: http://www.apache.org/licenses/LICENSE-2.0