
Thread-safe container for sharing data between threads. Header-only.
- Thread-safe push and fetch.
- Use stream operators to push (<<) and fetch (>>) items.
- Value type must be default constructible.
- Blocking (forever waiting to fetch).
- Range-based for loop supported.
- Close to prevent pushing and stop waiting to fetch.
- Integrates well with STL algorithms in some cases. Eg: std::move(ch.begin(), ch.end(), ...).
- Tested with GCC, Clang, and MSVC.
Requirements
Installation
Copy the include directory to your project and add it to your include path. Or see CMakeLists.txt from the CMake project example.
Usage
++
#include <cassert>
#include <msd/channel.hpp>
int main() {
int in = 1;
int out = 0;
chan << in;
chan >> out;
assert(out == 1);
}
Thread-safe container for sharing data between threads.
Definition channel.hpp:45
++
#include <msd/channel.hpp>
int main() {
chan << 1;
chan << 2;
chan << 3;
}
++
#include <msd/channel.hpp>
int main() {
int in = 1;
int out = 0;
chan << in;
chan << in;
chan >> out;
chan >> out;
chan >> out;
}
++
#include <iostream>
#include <msd/channel.hpp>
int main() {
int in1 = 1;
int in2 = 2;
chan << in1 << in2;
for (const auto out : chan) {
std::cout << out << '\n';
}
}
See examples.
Developed with CLion and Visual Studio Code.