Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
L

libco

> 编程语言
Open source

libco is a coroutine library which is widely used in wechat back-end service. It has been running on tens of thousands of machines since 2013.

8.7K stars0 likes2 views
WebsiteGitHub

About

libco is a coroutine library which is widely used in wechat back-end service. It has been running on tens of thousands of machines since 2013.

Libco

Libco is a c/c++ coroutine library that is widely used in WeChat services. It has been running on tens of thousands of machines since 2013.

By linking with libco, you can easily transform synchronous back-end service into coroutine service. The coroutine service will provide out-standing concurrency compare to multi-thread approach. With the system hook, You can easily coding in synchronous way but asynchronous executed.

You can also use co_create/co_resume/co_yield interfaces to create asynchronous back-end service. These interface will give you more control of coroutines.

By libco copy-stack mode, you can easily build a back-end service support tens of millions of tcp connection.


简介

libco是微信后台大规模使用的c/c++协程库,2013年至今稳定运行在微信后台的数万台机器上。

libco通过仅有的几个函数接口 co_create/co_resume/co_yield 再配合 co_poll,可以支持同步或者异步的写法,如线程库一样轻松。同时库里面提供了socket族函数的hook,使得后台逻辑服务几乎不用修改逻辑代码就可以完成异步化改造。

作者: sunnyxu([email protected]), leiffyli([email protected]), [email protected]([email protected]), sarlmolchen([email protected])

PS: 近期将开源PaxosStore,敬请期待。

libco的特性

  • 无需侵入业务逻辑,把多进程、多线程服务改造成协程服务,并发能力得到百倍提升;
  • 支持CGI框架,轻松构建web服务(New);
  • 支持gethostbyname、mysqlclient、ssl等常用第三库(New);
  • 可选的共享栈模式,单机轻松接入千万连接(New);
  • 完善简洁的协程编程接口
  • 类pthread接口设计,通过co_create、co_resume等简单清晰接口即可完成协程的创建与恢复;
  • __thread的协程私有变量、协程间通信的协程信号量co_signal (New);
  • 语言级别的lambda实现,结合协程原地编写并执行后台异步任务 (New);
  • 基于epoll/kqueue实现的小而轻的网络框架,基于时间轮盘实现的高性能定时器;

Build

bash
$ cd /path/to/libco
$ make

or use cmake

bash
$ cd /path/to/libco
$ mkdir build
$ cd build
$ cmake ..
$ make

Issues· 135 open

View all issuesOpen on GitHub
  • #173

    腾讯C++代码风格与易读性都这样吗?

    Updated Feb 12, 2026
  • #212

    期望支持一下跨平台,比如Windows

    Updated Feb 4, 2026
  • #209

    if a variable defined by CO_ROUTINE_SPECIFIC is referenced in multiple cpps, multiple instances of the variable will be generated under release build

    Updated Oct 1, 2025
  • #220

    co_get_curr_thread_env 崩溃

    Updated Mar 27, 2025
  • #219

    mkdir build;cmake .. 有问题啊,符号找不到:undefined reference to `clsCoMutex::clsCoMutex()'

    Updated Jan 23, 2025
  • #216

    如何为一个调用了gethostbyname的协程设置超时时间?

    Updated Oct 12, 2024
  • #135

    使用jemalloc导致deadlock

    Updated Oct 11, 2024
  • #151

    使用 cmake 编译出现 undefined exception 错误

    Updated Oct 2, 2024
  • #150

    请问ARM架构支持吗,谢谢

    Updated Apr 25, 2024
  • #215

    libcolib.so动态库存在内存泄漏问题

    Updated Apr 24, 2024

> Tags

C++

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 30, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言