tidwall/neco
FreeConcurrency library for C (coroutines)
About tidwall/neco
Neco is a small, fast C library that provides concurrency using coroutines, designed to simplify concurrent I/O and network programming. It features a lightweight runtime with a fair and deterministic scheduler, fast user-space context switching (using assembly where possible), and stackful coroutines whose lifetimes are fully managed by the scheduler. The library offers coroutine operations (start, sleep, suspend, resume, yield, join), synchronization primitives (channels, generators, mutexes, condition variables, waitgroups), support for deadlines and cancellation, and a Posix-friendly interface using file descriptors. Additional APIs include networking, signals, random data, streams, and buffered I/O. Neco is cross-platform (Linux, macOS, FreeBSD; limited support for WebAssembly and Windows) and distributed as a single-file amalgamation with no dependencies, achieving 100% test coverage with sanitizers and Valgrind.
Key Features
Pros & Cons
- Small and fast execution with minimal overhead
- Easy to use: just drop two files into a project
- Comprehensive synchronization primitives (channels, mutexes, etc.)
- Cross-platform support for multiple operating systems
- No external dependencies, simplifying integration
- Well-tested with full code coverage and sanitizer checks
- Single-threaded runtime only; not designed for multi-core parallelism
- Limited to C language; no direct support for C++ or other languages
- Windows and WebAssembly support have limitations (not fully featured)
- Not suitable for CPU-bound workloads requiring true parallelism
- Manual integration required (no package manager or build system automation)