Analysis updated 2026-07-03
Replace OS threads with coroutines in a high-performance C server to handle thousands of connections with less overhead.
Run millions of lightweight concurrent tasks in a single thread using shared stack mode when memory is limited.
Use libaco as the coroutine foundation for a custom async I/O framework in C.
Study the formal correctness proof to verify the context switching implementation before using it in production.
| hnes/libaco | linw7/skill-tree | aubio/aubio | |
|---|---|---|---|
| Stars | 3,684 | 3,686 | 3,702 |
| Language | C | C | C |
| Setup difficulty | moderate | easy | easy |
| Complexity | 4/5 | 1/5 | 3/5 |
| Audience | developer | developer | developer |
Figures from each repo's GitHub metadata at analysis time.
Only supports x86 and x86_64 processors via Sys V ABI, no ARM or Windows support.
Libaco is a small C library that lets programs run multiple tasks cooperatively within a single thread, a technique called coroutines. Normally when a program runs multiple things at once it uses threads, where the operating system decides when to switch between them. With coroutines, the code itself decides when to pause one task and hand control to another. This can be much faster because it avoids the overhead of the operating system stepping in. The library is designed for speed. The README reports that switching between coroutines takes about 10 nanoseconds on a typical cloud server when using the standalone stack mode. The entire implementation is under 700 lines of code. It currently supports the standard calling conventions (Sys V ABI) for 32-bit and 64-bit Intel processors. A key design feature is how it handles memory for each coroutine's stack. Libaco offers two options. A coroutine can have its own dedicated stack, which is fast to switch to but uses more memory. Alternatively, multiple coroutines can share a single stack, with each coroutine saving a copy of the relevant portion when it pauses and restoring it when it resumes. The shared stack approach is very memory efficient: the README demonstrates running 10 million simultaneous coroutines using only 2.8 gigabytes of physical memory when each coroutine uses a small copy-stack configuration. The README also includes a formal mathematical proof of correctness for the context switching implementation, explaining in detail how the CPU registers and stack state are saved and restored. This is unusual for a library of this type and is aimed at developers who want to verify that the underlying mechanism is sound before relying on it in production. The library is described as production-ready. The API is small: functions to create and destroy coroutines and shared stacks, and functions to resume and yield between them. The full README is longer than what was shown.
Libaco is a tiny C library under 700 lines that implements fast cooperative coroutines, switching between tasks in about 10 nanoseconds and supporting both dedicated and shared stack modes for running millions of lightweight concurrent tasks.
Mainly C. The stack also includes C, x86, x86_64.
Setup difficulty is rated moderate, with roughly 30min to a first successful run.
Mainly developer.
This repo across BitVibe Labs
Verify against the repo before relying on details.