Skip to content

drew-chen/Task-Runtime

Repository files navigation

Task Runtime

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 the Runtime is 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 void or value results through futures
  • Propagates task exceptions through futures
  • Runtime destruction waits for submitted work to finish
  • Dropping a Future does 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();

Requirements

Linux Packages

sudo apt update

sudo apt install \
    build-essential \
    gcc g++ \
    clang clangd clang-tidy \
    cmake \
    ninja-build \
    gdb \
    valgrind

Tooling Overview

CMake

Project/build system generator.

GCC

Primary production compiler.

Clang

Recommended development compiler.


Build Presets

This project uses CMakePresets.json for simplified builds.

Available presets:

  • gcc-debug
  • clang-debug
  • gcc-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.


Build And Test

cmake --workflow means configure the preset, build the targets, and run the tests.

Clang Debug

cmake --workflow --preset clang-debug

GCC Release

cmake --workflow --preset gcc-release

Test Only

Run all registered test cases after a build:

ctest --preset clang-debug

Run one test case:

ctest --preset clang-debug -R RuntimeTest.ThirdTaskWaitsForWorkerAvailability

Run Example

./build/clang-debug/example_basic

For manual control, use the underlying configure, build, and ctest commands with the same preset name.


VSCode Setup

This repository is configured for clangd.

  1. Install the VSCode clangd extension.
  2. Configure the project with a preset, for example:
cmake --preset clang-debug
  1. Open the workspace in VSCode.
  2. 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

Sanitizers are enabled in debug presets.

They help detect:

  • memory bugs
  • undefined behavior

Recommended Development Workflow

Daily Development

  • clang-debug

Final Validation

  • gcc-release

Implementation

Detailed design notes live in DESIGN.md.

Language concepts:

  • concurrency
  • task scheduling
  • move semantics
  • templates

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages