Coros – A Modern C++ Library for Task Parallelism

Coros is a C++23 library for task-based parallelism that uses coroutines and the expected type. It offers ease of use with a simple interface and header-only installation. Key features include optimized performance, error management with std::expected, and support for monadic operations like chaining tasks. The library provides benchmarks for Fibonacci calculation and matrix multiplication to showcase performance. Documentation explains the three main components: ThreadPool for managing worker threads, Task for task containers, and Awaiters for controlling flow. Installation is straightforward, requiring adding headers to the project directory and setting the include path. The library supports creating, starting, waiting for, and chaining tasks efficiently. It is recommended to avoid capturing references when using lambda coroutines. Task objects store outcomes using std::expected and offer methods for accessing values and errors. Tasks support keywords like co_return and co_await for flow control and transformation. Enqueueing tasks with coros::enqueue_tasks schedules them into a thread pool without waiting for completion. Different versions of wait_tasks allow for synchronous and asynchronous task waiting, supporting tasks across thread pools. The library enables efficient task creation, execution, and management for parallel processing in C++ programs.

https://github.com/mtmucha/coros

To top