A minimal C++23 thread pool + future-based task runtime built as a learning excersize.
Features:
- Schedule independent tasks concurrently
Runtime::submit()is thread-safe and may be called concurrently from multiple threads while theRuntimeis alive- Stores submitted callables and arguments in a type-erased task wrapper for later execution
- Performs minimal copies when storing work for later execution
- rvalue callables and arguments are moved into task-owned storage without copies
- copyable lvalue callables and arguments are copied once into task-owned storage
- copy-only lvalue callables can also be submitted and run later
- stored callables and arguments preserve value category at invocation
- Retrieves
voidor value results through futures - Propagates task exceptions through futures
- Runtime destruction waits for submitted work to finish
- Dropping a
Futuredoes not cancel the task
// type-erased
auto future1 = runtime.submit(func1, arg1, arg2);
auto future2 = runtime.submit(func2, arg1);
// block thread until value is available
auto val1 = future1.await();
// progress can be made on future2 while waiting for future1
auto val2 = future2.await();sudo apt update
sudo apt install \
build-essential \
gcc g++ \
clang clangd clang-tidy \
cmake \
ninja-build \
gdb \
valgrindProject/build system generator.
Primary production compiler.
Recommended development compiler.
This project uses CMakePresets.json for simplified builds.
Available presets:
gcc-debugclang-debuggcc-release
The configure step also generates compile_commands.json at the repository root. VSCode and clangd
use that file for accurate diagnostics and code navigation.
cmake --workflow means configure the preset, build the targets, and run the tests.
cmake --workflow --preset clang-debugcmake --workflow --preset gcc-releaseRun all registered test cases after a build:
ctest --preset clang-debugRun one test case:
ctest --preset clang-debug -R RuntimeTest.ThirdTaskWaitsForWorkerAvailability./build/clang-debug/example_basicFor manual control, use the underlying configure, build, and ctest commands with the same
preset name.
This repository is configured for clangd.
- Install the VSCode
clangdextension. - Configure the project with a preset, for example:
cmake --preset clang-debug- Open the workspace in VSCode.
- If diagnostics do not appear immediately, run
clangd: Restart language server.
The workspace settings in .vscode/settings.json are already set up to point clangd at
compile_commands.json.
Include-hygiene checks are configured in .clang-tidy. Some missing direct includes may show up in
clang-tidy before they appear as clangd squigglies.
Sanitizers are enabled in debug presets.
They help detect:
- memory bugs
- undefined behavior
Daily Development
clang-debug
Final Validation
gcc-release
Detailed design notes live in DESIGN.md.
Language concepts:
- concurrency
- task scheduling
- move semantics
- templates