tidwall/neco logo

tidwall/neco

Free

Concurrency library for C (coroutines)

FreeFree tier
Type
Open Source
Company
tidwall

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

Coroutines: start, sleep, suspend, resume, yield, and join
Synchronization: channels, generators, mutexes, condition variables, and waitgroups
Support for deadlines and cancellation
Posix-friendly interface using file descriptors
APIs for networking, signals, random data, streams, and buffered I/O
Lightweight runtime with fair and deterministic scheduler
Fast user-space context switching using assembly
Stackful coroutines fully managed by the scheduler
Cross-platform: Linux, macOS, FreeBSD; limited support for WebAssembly and Windows
Single file amalgamation with no dependencies

Pros & Cons

Pros
  • 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
Cons
  • 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)

Best For

Concurrent network programming in CBuilding single-threaded concurrent I/O applicationsReplacing pthreads with a simpler coroutine modelEmbedding coroutine-based concurrency in larger C projectsEducational exploration of coroutines and concurrency

FAQ

How do I start using Neco?
Simply download 'neco.c' and 'neco.h' and drop them into your C project. Compile with any modern C compiler (e.g., cc -c neco.c) and link.
What platforms are supported?
Neco supports Linux, macOS, and FreeBSD. It also has limited support for WebAssembly and Windows.
Does Neco support multithreading?
No, Neco provides single-threaded concurrency using coroutines. It is not designed to share the scheduler across multiple CPU cores.
What are the dependencies?
Neco has no dependencies. It is a single-file library that requires only a C compiler.
Is Neco production-ready?
The library is well-tested with 100% code coverage using sanitizers and Valgrind, and is used in projects like Bluebox for concurrent networking.