|
JH-Toolkit v1.4.1
An engineering-oriented C++20 toolkit with duck-typed concepts, static design, async coroutines, and semantic containers — header-only, RTTI-free, and concurrency-friendly.
|
Coroutine-based fiber for modern C++20. More...
#include <coroutine>#include <utility>#include <stdexcept>Go to the source code of this file.
Classes | |
| struct | jh::async::resume_t |
Tag type used to trigger a co_await inside a fiber. More... | |
| class | jh::async::fiber |
| Coroutine-based fiber providing manual suspension and resumption. More... | |
| struct | jh::async::fiber::promise_type |
Namespaces | |
| namespace | jh::async |
| Aggregated entry point for coroutine-based asynchronous facilities. | |
Variables | |
| resume_t | jh::async::resume_tag {} |
Global constant instance of resume_t. | |
Coroutine-based fiber for modern C++20.
This file defines a lightweight coroutine-based execution unit named fiber. A fiber represents a resumable coroutine without scheduling support. Its behavior is conceptually aligned with a thread blocked on condition_variable.wait(), but with significantly lower overhead.
noexcept. std::terminate(). co_return or co_yield like a generator; this makes exception masking mandatory. The fiber object can be resumed repeatedly using resume() until it reaches its final suspend point. The type does not integrate with an external scheduler and does not provide automatic continuation handling.
The behavior of jh::async::fiber depends primarily on the compiler frontend rather than the underlying standard library implementation.
Clang's coroutine lowering is fully conforming for this use-case. Lambda-based coroutine construction behaves correctly, temporary objects are tracked properly, and fiber lifetimes remain well-defined.
GCC (14 and 15 tested) exhibits a frontend issue when a coroutine is produced directly from an immediately-invoked lambda:
In this form, GCC may mis-handle the lifetime and binding of the temporary lambda object, leading to premature destruction of the coroutine frame or dangling references during suspension. This is a frontend analysis problem, not a runtime or ABI limitation.
The safe construction pattern is:
This avoids the temporary-lifetime misanalysis and ensures fully correct coroutine behavior on all tested platforms.
Summary:
fiber usage. 1.4.x
2025