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

Opt-in experimental coroutine-friendly bridge over ThreadPool. More...

#include <ah-errors.H>
#include <thread_pool.H>
Include dependency graph for experimental_async.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ALEPH_ENABLE_EXPERIMENTAL_ASYNC   0
 
#define ALEPH_DETAIL_HAS_COROUTINE_HEADER   0
 
#define ALEPH_HAS_EXPERIMENTAL_ASYNC   0
 

Detailed Description

Opt-in experimental coroutine-friendly bridge over ThreadPool.

This header intentionally keeps a very small scope. It does not attempt to redesign Aleph-w around coroutines or provide a full sender/receiver framework. Instead it offers:

  • Aleph::experimental::scheduled_operation: a move-only awaitable result handle for work scheduled on a ThreadPool
  • Aleph::experimental::schedule(): submit a callable to a pool and obtain a scheduled_operation

The bridge is disabled by default. To enable it, build or compile with ALEPH_ENABLE_EXPERIMENTAL_ASYNC=1 and a C++20 compiler that provides <coroutine>. When these conditions are not met, the header still defines ALEPH_HAS_EXPERIMENTAL_ASYNC as 0, but no experimental async API is declared.

Portability assessment for Aleph-w's current targets:

  • GCC 11+ with -std=c++20 provides the coroutine support needed here
  • Clang 14+ with -std=c++20 likewise supports this limited bridge
  • below C++20 this header simply stays disabled; it does not introduce a new coroutine requirement for code that does not opt into the bridge
  • MSVC remains outside Aleph-w's documented support matrix

Design constraints:

  • completion resumes an awaiting coroutine on the worker thread that finishes the scheduled callable
  • each scheduled_operation<T> has single-consumer semantics, like std::future<T>
  • return-by-reference is intentionally rejected; return a value or std::reference_wrapper<T> instead

Example:

#include <thread_pool.H>
#if ALEPH_HAS_EXPERIMENTAL_ASYNC
auto op = Aleph::experimental::schedule(pool, [] { return 42; });
int value = op.get();
(void) value;
#endif
A reusable thread pool for efficient parallel task execution.
Opt-in experimental coroutine-friendly bridge over ThreadPool.
A modern, efficient thread pool for parallel task execution.

See docs/experimental_async_bridge.md and Examples/experimental_async_example.cc.

Definition in file experimental_async.H.

Macro Definition Documentation

◆ ALEPH_DETAIL_HAS_COROUTINE_HEADER

#define ALEPH_DETAIL_HAS_COROUTINE_HEADER   0

Definition at line 109 of file experimental_async.H.

◆ ALEPH_ENABLE_EXPERIMENTAL_ASYNC

#define ALEPH_ENABLE_EXPERIMENTAL_ASYNC   0

Definition at line 94 of file experimental_async.H.

◆ ALEPH_HAS_EXPERIMENTAL_ASYNC

#define ALEPH_HAS_EXPERIMENTAL_ASYNC   0

Definition at line 119 of file experimental_async.H.