wangbojing/NtyCo logo

wangbojing/NtyCo

Free

纯c版本的协程实现,汇编切换,调度器实现,包含服务器端案例,客户端并发测试案例

FreeFree tier
Type
Open Source

About wangbojing/NtyCo

NtyCo is a pure C coroutine implementation with assembly-level context switching and a scheduler featuring a finite state machine (FSM) for managing coroutine states (ready, wait, sleep, etc.). It includes a static library (libntyco.a) and multiple sample applications such as a multi-process, multi-core HTTP server, a WebSocket server, a benchmark tool, and a client concurrency test. The project also provides supporting video explanations and is designed for learning and building high-concurrency network servers.

Key Features

Pure C coroutine implementation with assembly-level context switching
Scheduler with finite state machine handling ready, wait, and sleep states
Static library (libntyco.a) for easy integration
Sample server applications: multi-core HTTP server, WebSocket server, echo server
Client concurrency test tool and benchmark utility
Multi-process and multi-core support demonstrated in samples
Includes webbench and tinyhttpd integration
Video explanation of the coroutine implementation principle

Pros & Cons

Pros
  • Fast context switching using assembly for minimal overhead
  • Lightweight and minimal dependencies – pure C with no external runtime
  • Comes with multiple real-world sample applications for rapid prototyping
  • Includes video tutorial for deeper understanding
  • Open source with permissive licensing (MIT implied by GitHub)
Cons
  • Limited to C programming language, not usable directly from other languages
  • Requires manual memory management as typical in C
  • Documentation and comments primarily in Chinese
  • Less feature-rich compared to modern coroutine libraries in C++ (e.g., Boost.Coroutine) or Go

Best For

Building high-concurrency network servers (HTTP, WebSocket) in CLearning coroutine principles and implementation through practical examplesConcurrent client testing and benchmarkingEmbedding a lightweight coroutine scheduler into C applications

FAQ

How do I compile the static library?
Run 'make' in the project root to build libntyco.a. To compile sample binaries, run 'make bin'.
I get a fatal error: mysql.h: No such file or directory. How to fix?
Install the MySQL client development package using 'sudo apt-get install libmysqlclient-dev'.
I get a fatal error: hiredis.h: No such file or directory. How to fix?
Install the hiredis library from https://github.com/redis/hiredis by compiling it manually.
How do I run the sample HTTP server?
Compile with 'make bin', then run './bin/nty_http_server_mulcore' for a multi-core HTTP server.
What is the purpose of the FSM in the scheduler?
The finite state machine manages coroutine states (ready, wait, sleep, status) to efficiently schedule execution.