Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
concurrency_utils.H File Reference

Modern synchronization helpers for channels, shared state, and small producer-consumer queues. More...

#include <atomic>
#include <condition_variable>
#include <concepts>
#include <cstddef>
#include <deque>
#include <functional>
#include <mutex>
#include <optional>
#include <shared_mutex>
#include <stdexcept>
#include <type_traits>
#include <utility>
#include <vector>
#include <thread_pool.H>
Include dependency graph for concurrency_utils.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  Aleph::BoundedChannel< T >
 Bounded blocking channel for producer-consumer workflows. More...
 
class  Aleph::Synchronized< T, Mutex >
 Mutex-protected shared object wrapper. More...
 
class  Aleph::Synchronized< T, Mutex >::LockedPtr
 RAII guard for exclusive access to the synchronized value. More...
 
class  Aleph::Synchronized< T, Mutex >::ConstLockedPtr
 RAII guard for read-only access to the synchronized value. More...
 
class  Aleph::RwSynchronized< T, SharedMutex >
 Read/write-lock protected shared object wrapper. More...
 
class  Aleph::RwSynchronized< T, SharedMutex >::ReadLockedPtr
 RAII guard for shared (read-only) access. More...
 
class  Aleph::RwSynchronized< T, SharedMutex >::WriteLockedPtr
 RAII guard for exclusive (write) access. More...
 
class  Aleph::SpscQueue< T >
 Bounded single-producer/single-consumer queue. More...
 

Namespaces

namespace  Aleph
 Main namespace for Aleph-w library functions.
 

Typedefs

template<typename T >
using Aleph::bounded_channel = BoundedChannel< T >
 Alias for Aleph::BoundedChannel.
 
template<typename T , typename Mutex = std::mutex>
using Aleph::synchronized = Synchronized< T, Mutex >
 Alias for Aleph::Synchronized.
 
template<typename T , typename SharedMutex = std::shared_mutex>
using Aleph::rw_synchronized = RwSynchronized< T, SharedMutex >
 Alias for Aleph::RwSynchronized.
 
template<typename T >
using Aleph::spsc_queue = SpscQueue< T >
 Alias for Aleph::SpscQueue.
 

Detailed Description

Modern synchronization helpers for channels, shared state, and small producer-consumer queues.

This header complements thread_pool.H with a few focused utilities for practical concurrent code:

These facilities intentionally keep a small API surface. They are suitable for everyday coordination tasks and can be combined with ThreadPool, TaskGroup, and the parallel algorithms introduced in earlier phases.

Example:

#include <thread_pool.H>
Aleph::synchronized<std::vector<int>> results(std::in_place);
pool.enqueue_detached([&] {
for (int i = 1; i <= 10; ++i)
jobs.send(i);
jobs.close();
});
Aleph::TaskGroup workers(pool);
for (int w = 0; w < 2; ++w)
workers.launch([&] {
while (auto item = jobs.recv())
results.with_lock([&](auto &out) { out.push_back(*item * 2); });
});
workers.wait();
long double w
Definition btreepic.C:153
Bounded blocking channel for producer-consumer workflows.
Mutex-protected shared object wrapper.
Minimal structured-concurrency helper over ThreadPool futures.
A reusable thread pool for efficient parallel task execution.
Modern synchronization helpers for channels, shared state, and small producer-consumer queues.
A modern, efficient thread pool for parallel task execution.

For legacy POSIX wrappers see useMutex.H and useCondVar.H. New code should generally prefer this header together with standard C++ mutexes and condition variables.

BoundedChannel also offers overloads that accept Aleph::CancellationToken. These preserve the same close semantics but throw Aleph::operation_canceled if cancellation is requested while a sender or receiver is blocked waiting for space or data.

Definition in file concurrency_utils.H.