# tencent/libco

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/tencent-libco).**

8,684 stars · 2,120 forks · C++ · NOASSERTION

## Links

- GitHub: https://github.com/Tencent/libco
- awesome-repositories: https://awesome-repositories.com/repository/tencent-libco.md

## Description

libco is a C++ coroutine library and user-space task orchestrator designed for cooperative multitasking and high-concurrency execution. It functions as a high-concurrency network framework and a synchronous-to-asynchronous wrapper that allows blocking system calls and socket functions to run asynchronously without modifying existing business logic.

The project utilizes a specialized stack-copying context switching model to support millions of simultaneous TCP connections on a single machine. It includes a high-performance time wheel scheduler for managing asynchronous background jobs and delayed operations with constant-time complexity.

The library provides capabilities for fine-grained task switching and concurrent state management, using private variables and signals for communication between coroutines. It integrates non-blocking I/O and system-call interception to manage the lifecycle of lightweight threads without relying on kernel-level preemption.

## Tags

### Software Engineering & Architecture

- [Cooperative Schedulers](https://awesome-repositories.com/f/software-engineering-architecture/task-scheduling/asynchronous-schedulers/cooperative-schedulers.md) — Implements a cooperative scheduler where tasks voluntarily yield control to manage high-concurrency execution flow.
- [Non-blocking I/O](https://awesome-repositories.com/f/software-engineering-architecture/concurrent-task-execution/non-blocking-i-o.md) — Integrates non-blocking I/O to handle millions of concurrent network connections without blocking the main execution thread.
- [Concurrent State Coordination](https://awesome-repositories.com/f/software-engineering-architecture/concurrent-state-coordination.md) — Coordinates communication and shared state between concurrent tasks using signals and private variables.
- [Coroutine Private Variables](https://awesome-repositories.com/f/software-engineering-architecture/state-management/object-state-trackers/state-member-variables/coroutine-private-variables.md) — Allocates dedicated memory regions for each coroutine to maintain local state and variables across execution suspensions.

### Development Tools & Productivity

- [User-Space Concurrency](https://awesome-repositories.com/f/development-tools-productivity/parallel-execution/action-concurrency/user-space-concurrency.md) — Orchestrates the creation, resumption, and yielding of concurrent tasks in user-space to avoid blocking the main thread.
- [Time Wheel Schedulers](https://awesome-repositories.com/f/development-tools-productivity/background-task-schedulers/time-wheel-schedulers.md) — Provides a high-performance time wheel mechanism for executing asynchronous background jobs and delayed operations. ([source](https://github.com/tencent/libco#readme))

### Networking & Communication

- [High-Concurrency Networking](https://awesome-repositories.com/f/networking-communication/high-concurrency-networking.md) — Handles millions of simultaneous TCP connections on a single machine using lightweight coroutines.
- [Coroutine Channels](https://awesome-repositories.com/f/networking-communication/distributed-systems-p2p/peer-to-peer-networking/state-synchronization/coroutine-channels.md) — Implements a system for sharing private variables and signals to coordinate state and communication between coroutines. ([source](https://github.com/tencent/libco#readme))

### Operating Systems & Systems Programming

- [Stack-Copying Context Switches](https://awesome-repositories.com/f/operating-systems-systems-programming/stack-copying-context-switches.md) — Saves and restores CPU registers and memory segments by copying the coroutine stack to enable high-density concurrency.
- [Synchronous-to-Asynchronous Wrappers](https://awesome-repositories.com/f/operating-systems-systems-programming/synchronous-to-asynchronous-wrappers.md) — Provides a mechanism to intercept system calls and socket functions, allowing synchronous business logic to execute asynchronously. ([source](https://github.com/tencent/libco#readme))
- [System-Call Interception](https://awesome-repositories.com/f/operating-systems-systems-programming/system-call-interception.md) — Wraps blocking I/O and socket functions to yield execution back to the scheduler until resources become available.
- [Fine-Grained Task Switching](https://awesome-repositories.com/f/operating-systems-systems-programming/fine-grained-task-switching.md) — Controls the execution lifecycle of coroutines to switch between functions without blocking the main thread.

### Programming Languages & Runtimes

- [Concurrent Thread Execution](https://awesome-repositories.com/f/programming-languages-runtimes/concurrent-thread-execution.md) — Enables pausing and resuming multiple functions to handle high volumes of concurrent processing. ([source](https://github.com/tencent/libco#readme))
- [Coroutine Libraries](https://awesome-repositories.com/f/programming-languages-runtimes/high-performance-c-libraries/coroutine-libraries.md) — Provides a C++ library for managing cooperative multitasking and high-concurrency execution through lightweight user-space threads.
- [Coroutines](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/concurrency-models/concurrency/synchronization-primitives/channel-based-concurrency/fiber-based-schedulers/coroutines.md) — Provides a minimal interface for creating, resuming, and yielding execution between coroutines for fine-grained task switching. ([source](https://github.com/tencent/libco#readme))

### DevOps & Infrastructure

- [Time Wheel Schedulers](https://awesome-repositories.com/f/devops-infrastructure/automation-orchestration/task-execution-frameworks/task-job-management/task-schedulers/delayed-task-scheduling/timed-event-scheduling/time-wheel-schedulers.md) — Uses a circular buffer to track and trigger timed events with constant-time complexity for high-performance task management.

### Scientific & Mathematical Computing

- [High-Performance Task Schedulers](https://awesome-repositories.com/f/scientific-mathematical-computing/high-performance-execution-environments/high-performance-and-parallel-computing/high-performance-computing/high-performance-task-schedulers.md) — Manages background jobs and timed operations using a high-performance time wheel to minimize overhead.

### Part of an Awesome List

- [Asynchronous Event Loops](https://awesome-repositories.com/f/awesome-lists/devtools/asynchronous-event-loops.md) — Coroutine-based library for high-concurrency I/O.
