explaingit

tencent/libco

8,677C++Audience · developerComplexity · 4/5Setup · moderate

TLDR

libco is Tencent's C/C++ coroutine library powering WeChat's backend since 2013, letting servers handle millions of concurrent connections efficiently by pausing and resuming lightweight tasks instead of spawning large numbers of threads.

Mindmap

mindmap
  root((libco))
    Core Concept
      Coroutines
      Pause and resume
      Non-blocking IO
    Usage Modes
      Hook mechanism
      Explicit co create
      Shared-stack mode
    Performance
      Millions of connections
      Low thread overhead
      WeChat production proven
    Setup
      make or cmake
      C and C++ API
      Minimal docs
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Convert existing C/C++ server code to use coroutines with minimal changes by enabling libco's hook mechanism on standard network calls.

USE CASE 2

Handle millions of concurrent TCP connections on a single machine using libco's shared-stack coroutine mode.

USE CASE 3

Build a high-performance C/C++ backend service that scales to high concurrency without the complexity of traditional multi-threading.

Tech stack

CC++makecmake

Getting it running

Difficulty · moderate Time to first run · 1h+

Requires building from source with make or cmake, documentation is minimal and assumes familiarity with C/C++ systems programming.

In plain English

libco is a C and C++ library from Tencent that has been used in WeChat's backend systems since 2013, running on tens of thousands of machines. It provides a way to write server-side code that handles many simultaneous tasks efficiently without the complexity of managing large numbers of threads. The core idea is coroutines, which are units of work that can pause and resume. When one coroutine is waiting on a slow operation like a network request, instead of blocking a thread while waiting, the system can switch to running another coroutine. This makes it possible to handle far more concurrent connections than a traditional multi-thread approach would allow on the same hardware. Libco offers two ways to use this. You can use a hook mechanism that intercepts standard network calls at the system level, which means existing code written in a straightforward sequential style can be converted to use coroutines with little or no changes to the business logic. Alternatively, you can use the explicit interfaces (co_create, co_resume, co_yield) to create and control coroutines directly with more fine-grained control. The library also includes a shared-stack mode for cases where you need to support tens of millions of TCP connections on a single machine. Building the library requires running make or cmake from the source directory. The README is brief and covers only the core description and build steps. Further documentation is limited.

Copy-paste prompts

Prompt 1
Show me how to create and switch between two coroutines using libco's co_create and co_resume interfaces in a minimal C++ example.
Prompt 2
How do I use libco's hook mechanism to convert an existing blocking C network server to use coroutines without rewriting the business logic?
Prompt 3
Set up a simple echo server in C using libco that can handle thousands of simultaneous connections using shared-stack mode.
Prompt 4
Build and link libco using cmake on Linux and write a coroutine that prints a message, yields back to the main routine, then resumes to finish.
Open on GitHub → Explain another repo

← tencent on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.