TooManyCooks is a runtime and concurrency library for C++20 coroutines. Its goals:
- be the fastest general-purpose coroutine library available (see the 📈 benchmarks)
- clean API with minimal noise
- extensive feature set
- simple and clear path to migrate legacy applications
- simple and clear path to integrate with 3rd-party executors/event loops
It provides:
- a blazing fast, lock-free, work-stealing, continuation-stealing thread pool (
ex_cpu) - automatic, hardware-optimized thread configuration via hwloc
- network I/O, file I/O, and timers support by integration with Asio (via
tmc-asio) - support for multiple task priority levels
- support for both coroutines and regular functors in most APIs
- a suite of utility functions for fluently interacting with tasks, awaitables, and executors
- a suite of async data and control structures
- a global executor instance so you can submit work from anywhere
- traits-based extensibility for 3rd party awaitables and executors
| 📄 Documentation | 💡 Examples | 📈 Benchmarks | ✅ Tests |
|---|
// A complete implementation of the parallel recursive fibonacci benchmark
#define TMC_IMPL
#include "tmc/all_headers.hpp"
#include <iostream>
tmc::task<int> fib(int n) {
if (n < 2) {
co_return n;
}
// Fork 2 child tasks in parallel and await both results.
// The return type of a single task would be just `int`.
// Here, we retrieve both results together in a `std::tuple<int, int>`.
auto [x, y] = co_await tmc::spawn_tuple(fib(n - 1), fib(n - 2));
co_return x + y;
}
int main() {
// Manually construct an executor and block on a root task.
// `tmc::async_main()` could be used instead to simplify this.
tmc::cpu_executor().init();
// Synchronous (blocking) APIs return a std::future.
int result = tmc::post_waitable(tmc::cpu_executor(), fib(30)).get();
std::cout << result << std::endl;
}TooManyCooks is a header-only library. Adding it to your project is simple:
- Download the library and add
/includeto your include path. - Add
#define TMC_IMPLand#include "tmc/all_headers.hpp"to exactly one file in your project.
For a minimal project template, see
tmc-hello-world.
TooManyCooks will work out of the box as a header-only library without any configuration. However, some performance tuning options are available. See the documentation section Build-Time Options for more info.
- v1.3: hwloc improvements (CPU topology query, P and E core detection, container CPU quota detection, unlimited threads)
- v1.4: awaitable traits / concepts, zero-copy channel, awaitable result streaming
- Beyond: See the issues tagged "enhancement" for future planned work. Please leave a 👍 on any issues that are important to you. I will use this as a way to gauge community interest on what should be developed next.
All 3 major compilers are fully supported, but Clang is the recommended compiler, as it has the best coroutine codegen and the most functional HALO implementation.
Linux:
- Clang 17 or newer
- GCC 14 or newer
Windows:
- Clang 17 or newer (via clang-cl.exe)
- MSVC Build Tools v145 (Visual Studio 2026 Insiders) or newer (older versions are affected by this bug)
MacOS:
- Apple Clang based on Clang 17 or newer with -fexperimental-library
- x86 (32- or 64-bit)
- AArch64
TooManyCooks is regularly tested on the following physical devices:
- Intel i7 4770K
- Intel i5 13600K
- AMD Ryzen 5950X
- AMD EPYC 7742
- Apple M2
- Rockchip RK3588S (in a Khadas Edge2)