cpp-asyncworker
Welcome to the cpp-asyncworker documentation! This is a lightweight, thread-safe, and header-only C++ library for managing asynchronous tasks using a worker pool.
Features
- Header-Only & Easy Integration: Simply copy
cppasyncworker.hppinto your project, or integrate it seamlessly via modern CMake (FetchContentoradd_subdirectory()). - Flexible Task Execution: Enqueue any callable object—lambdas, function pointers, functors, or
std::bindexpressions—along with any number of arguments. - Futures Integration: Returns a
std::futurefor every enqueued task, allowing you to easily retrieve return values or block until completion. - Exception Propagation: Exceptions thrown within worker threads are safely caught and re-thrown in the calling thread when you call
.get()on the task’s future. - Hardware-Aware Concurrency: Automatically defaults to the optimal number of worker threads based on your system’s hardware concurrency.
- Standard C++: Built purely on standard
<thread>,<mutex>,<condition_variable>, and<future>to ensure maximum compatibility and thread safety without any external dependencies.
Table of Contents
- Getting Started - Installation and requirements.
- Basic Usage - Basic usage of the
WorkerPool. - Advanced Usage - Handling return values, futures, and synchronization.