20 std::cout <<
"Example 1: bounded_channel with TaskGroup\n";
28 for (
int i = 1; i <= 8; ++i)
33 for (
int worker = 0; worker < 2; ++worker)
35 while (
auto item = jobs.
recv())
38 out.push_back(*item * *item);
46 auto sorted = squares.with_lock([](
const auto &
out) {
52 std::cout <<
"Squares:";
53 for (
const int value : sorted)
55 std::cout <<
"\nProcessed count: "
56 << processed.with_read_lock([](
const int &
value) {
return value; })
59 std::cout <<
"Example 2: cancellation-aware recv\n";
65 (void) canceled.recv(stop.
token());
66 std::cout <<
"unexpected success\n";
70 std::cout <<
"recv interrupted by cancellation\n";
73 std::cout <<
"\nExample 3: spsc_queue handoff\n";
77 auto first = handoff.try_pop();
78 auto second = handoff.try_pop();
79 std::cout <<
"Popped:";
80 if (first.has_value())
81 std::cout <<
" " << *first;
82 if (second.has_value())
83 std::cout <<
" " << *second;
size_t size_t int32_t value
size_t size_t int32_t * out
Bounded blocking channel for producer-consumer workflows.
bool recv(T &out)
Receive an item from the channel into out.
void close()
Close the channel.
bool send(const T &value)
Send a value by copying it into the channel.
Cooperative cancellation source paired with CancellationToken.
CancellationToken token() const noexcept
Return a token observing this source.
void request_cancel() noexcept
Request cancellation for all derived tokens.
Read/write-lock protected shared object wrapper.
decltype(auto) with_write_lock(F &&f)
Execute a callback with exclusive (write) access.
Bounded single-producer/single-consumer queue.
Mutex-protected shared object wrapper.
decltype(auto) with_lock(F &&f)
Execute a callback with exclusive access to the value.
Minimal structured-concurrency helper over ThreadPool futures.
void launch(F &&f, Args &&... args)
Launch a task that belongs to this group.
A reusable thread pool for efficient parallel task execution.
Exception thrown when cooperative cancellation is observed.
Modern synchronization helpers for channels, shared state, and small producer-consumer queues.
Main namespace for Aleph-w library functions.
Itor2 copy(Itor1 sourceBeg, const Itor1 &sourceEnd, Itor2 destBeg)
Copy elements from one range to another.
A modern, efficient thread pool for parallel task execution.