Download Latest Version coost v4.0.0 release source code.zip (284.0 kB) Google Add to Preferred Sources
Home / v4.0.0
Name Modified Size InfoDownloads / Week
Parent folder
coost v4.0.0 release source code.tar.gz 2026-09-15 215.8 kB
coost v4.0.0 release source code.zip 2026-09-15 284.0 kB
README.md 2026-09-15 11.2 kB
Totals: 3 Items   511.0 kB 0

简体中文

coost v4.0.0 发布

coost v4.0.0 是一次较大的版本更新:编译器要求提升至 C++17,移除了若干维护成本较高的模块,新增 Windows ARM64 与 FreeBSD 平台支持,并对核心组件进行了性能优化与 API 整理。升级前请先阅读下方的破坏性变更。

1. 破坏性变更

编译器要求 C++17

旧版本中的流式日志写法:

:::cpp
LOG << "hello " << 23;

在本版本中被替换为更安全、更直观的函数式写法:

:::cpp
log::info("hello ", 23);
log::warn("hello ", 23);

该写法依赖 C++17,目前主流编译器对 C++17 的支持已经成熟,因此本版本将最低标准提升到 C++17。

不再支持动态库

动态库的维护成本较高,需要在每个导出符号上加 __coapi,容易遗漏。本版本不再提供动态库支持,有需要的用户可以自行将 coost 封装成动态库。

移除 hook 功能

协程 hook 依赖的 fishhook、detours 在 GitHub 上已多年未更新,且 hook 面临的环境复杂,难以在各平台提供统一且稳定的实现。为降低维护负担,本版本移除了 hook 功能。如有定制化的 hook 需求,作者提供针对特定平台的付费服务。

移除 HTTP、SSL 等网络组件

这些组件依赖 libcurl、openssl 等第三方库,维护成本较高,本版本予以移除。有需要的用户可以从旧版本中获取相关代码自行维护。

移除 fastring、fastream

旧版本中的 fastring、fastream 已合并为 co::string,字符串相关的功能统一收敛到 co/string.h

移除协程 channel

channel 性能较差、代码维护困难,实际使用场景有限,本版本予以移除。

命名空间调整

本版本将大部分功能统一收敛到 co 命名空间中,仅保留以下几个独立命名空间:

模块 命名空间
命令行参数与配置解析 flag
日志组件 log
文件操作 fs
系统操作 os
JSON json
Path 组件 path

时间相关功能中,仅 time::sleep 保留在 time 命名空间,用于与协程中的 co::sleep 区分;其余时间相关内容全部移入 co 命名空间,例如:

:::cpp
co::now.ms();
co::now.str();
co::mono_time.us();

若要调用 C 标准库中的同名函数,请显式加全局作用域:

:::cpp
::log(...);
::time(0);

2. 新增平台支持

本版本新增对 Windows ARM64FreeBSD 的支持。构建与测试均已在 CI 中覆盖。

由于 FreeBSD 平台上 unix 是一个宏,原 co/time.h 中的以下接口:

:::cpp
time::unix.ms();
time::str();
time::mono.us();

调整为:

:::cpp
co::now.ms();
co::now.str();
co::mono_time.us();

3. 新增与优化

终端输出

终端输出功能迁移到 co/print.h,提供 co::printco::println 两个函数,并支持颜色:

:::cpp
co::color c;
co::print(c.red("red\n"));
co::println("hello ", c.red, "coost ", c.green, 123, c.deflt);

性能与易用性改进

  • benchmark:增加预热机制,新增 sub_group 功能;
  • 闭包(co/closure.h):抛弃原先基于继承与虚函数的实现,改为非模板、无虚函数的设计,性能更好,使用更方便;
  • 内置 flag:注释支持中英双语,并根据系统语言环境自动选择;
  • 日志组件:原先的 LOGELOG 等宏替换为 log::info()log::error() 等函数,更安全,也更便于调试;
  • co/rand.h:优化 co::randstr() 的性能与安全性;
  • 同步事件:优化跨线程的 co::sync_event,以及协程与线程混合环境下的 co::event;移除 signal 方法,新增 notify_onenotify_all
  • 协程同步原语:优化 co::mutexco::wait_group

4. Bug 修复

  • 修复 32 位 Windows 下程序崩溃时无法打印堆栈信息的问题;
  • 修复 macOS 下程序崩溃时无法打印堆栈信息的问题(依赖 libbacktrace,需要用户自行安装);
  • 修复 32 位 ARM 系统下,因协程 sp 未按 8 字节对齐导致的 bus error。

5. 迁移指南

旧接口 新接口
LOG << "..." << x; log::info("...", x);
ELOG << "..." << x; log::error("...", x);
time::unix.ms() co::now.ms()
time::str() co::now.str()
time::mono.us() co::mono_time.us()
fastring / fastream co::string
co::Json json::any
协程 channel 已移除
hook 已移除
HTTP / SSL 组件 已移除(可从旧版本取用)
动态库 已移除(用户可自行封装)

6. 结语

本次改动较大,参考文档已落后于最新代码,使用过程中请以实际代码为准。

整体而言,v4.0.0 的代码结构更加简洁,更贴合 coost 一贯的极简风格,使用体验也更加流畅。

为了能够持续维护与改进 coost,作者提供一些付费服务,详见 readme [页面](https://github.com/idealvin/coost/blob/master/readme_cn.md#1

English

coost v4.0.0 Release

coost v4.0.0 is a major update: the minimum C++ standard is now C++17, several modules with high maintenance overhead have been removed, Windows ARM64 and FreeBSD are newly supported, and the core components have received performance and API improvements. Please read the breaking changes below before upgrading.

1. Breaking Changes

Requires C++17

The streaming log syntax used in earlier versions:

:::cpp
LOG << "hello " << 23;

has been replaced by a safer, more intuitive functional style:

:::cpp
log::info("hello ", 23);
log::warn("hello ", 23);

This style relies on C++17. Since mainstream compilers now support C++17 well, the minimum required standard has been raised to C++17.

Dynamic library support removed

Dynamic libraries require __coapi on every exported symbol, which is easy to forget and costly to maintain. coost no longer ships as a dynamic library. Users who need one can wrap coost themselves.

Hook removed

The third-party libraries that coroutine hooks depend on (fishhook, detours) have not been updated on GitHub for years, and hooks are highly environment-dependent, making a stable cross-platform implementation impractical. To reduce maintenance burden, hook has been removed. Custom, platform-specific hooks are available as a paid service.

These components depend on third-party libraries such as libcurl and openssl, which are cumbersome to maintain. They have been removed in this version. Users who need them can refer to previous releases.

fastring and fastream removed

The old fastring and fastream have been merged into co::string, and all string-related utilities now live in co/string.h.

Coroutine channel removed

channel performed poorly, was hard to maintain, and saw little practical use. It has been removed.

Namespace reorganization

Most functionality has been consolidated into the co namespace. Only the following modules keep their own namespaces:

Module Namespace
Command-line and config parsing flag
Logging log
File operations fs
System operations os
JSON json
Path utilities path

Among the time-related utilities, only time::sleep remains in the time namespace, so that it can be distinguished from the coroutine-aware co::sleep. Everything else related to time has moved into the co namespace, for example:

:::cpp
co::now.ms();
co::now.str();
co::mono_time.us();

To call same-named functions from the C standard library, qualify them explicitly:

:::cpp
::log(...);
::time(0);

2. New Platform Support

This release adds support for Windows ARM64 and FreeBSD. Both are covered by CI builds and tests.

Because unix is a macro on FreeBSD, the following APIs in co/time.h:

:::cpp
time::unix.ms();
time::str();
time::mono.us();

have been renamed to:

:::cpp
co::now.ms();
co::now.str();
co::mono_time.us();

3. New Features and Improvements

Terminal output

Terminal output has moved to co/print.h, providing co::print and co::println, with color support:

:::cpp
co::color c;
co::print(c.red("red\n"));
co::println("hello ", c.red, "coost ", c.green, 123, c.deflt);

Performance and usability

  • benchmark: added warm-up and a new sub_group feature;
  • Closure (co/closure.h): rewritten from an inheritance / virtual-function design to a non-template, virtual-free implementation, yielding better performance and simpler usage;
  • Built-in flag: comments are now bilingual and automatically follow the system language;
  • Logging: the old LOG, ELOG macros have been replaced with log::info(), log::error(), etc., which are safer and easier to debug;
  • co/rand.h: improved performance and safety of co::randstr();
  • Sync events: improved co::sync_event for cross-thread use and co::event for mixed coroutine/thread use; removed signal and added notify_one / notify_all;
  • Coroutine primitives: improved co::mutex and co::wait_group.

4. Bug Fixes

  • Fixed stack traces not being printed on crash on 32-bit Windows;
  • Fixed stack traces not being printed on crash on macOS (depends on libbacktrace, which must be installed by the user);
  • Fixed a bus error on 32-bit ARM caused by the coroutine stack pointer not being 8-byte aligned.

5. Migration Guide

Old API New API
LOG << "..." << x; log::info("...", x);
ELOG << "..." << x; log::error("...", x);
time::unix.ms() co::now.ms()
time::str() co::now.str()
time::mono.us() co::mono_time.us()
fastring / fastream co::string
co::Json json::any
Coroutine channel Removed
Hook Removed
HTTP / SSL components Removed (refer to older releases)
Dynamic library Removed (wrap it yourself)

6. Closing

This is a large release. The reference documentation currently lags behind the latest source code; please refer to the code in case of discrepancy.

Overall, v4.0.0 is leaner and more consistent with coost's minimalist philosophy, and is more pleasant to use.

To support the ongoing maintenance and improvement of coost, the author offers paid services. See the [readme](https://github.com/idealvin/coost/blob/master/readme.md#1 for details.

Source: README.md, updated 2026-09-15