Zifeng Deng

Results 19 comments of Zifeng Deng

## 链接 mimalloc 静态库 根据[官方示例](https://github.com/microsoft/mimalloc/blob/dev/test/CMakeLists.txt#L30-L33),直接使用 `mimalloc-static` 很可能会不成功,官方建议尝试这么做: ```diff if (CO_CONTEXT_USE_MIMALLOC) - target_link_libraries(co_context PUBLIC mimalloc) + target_link_libraries(co_context PUBLIC ${MIMALLOC_OBJECT_DIR}/mimalloc.o) + target_include_directories(co_context PUBLIC ${MIMALLOC_INCLUDE_DIR}) endif() ``` ## 不使用 mimalloc 如果 cmake 没有找到...

> I think your project do well. And it has the newest feature both in C++ and the OS. But one important feature `modules` in `C++20` is missed. I think...

Thanks for you help! I'd love to, but I'm afraid it will be a little bit difficult to provide the module version directly without cmake, because this project detects the...

我对 Ubuntu 不是非常熟悉,猜测 Ubuntu20.04 是早于 Linux 5.6 的发行版,导致其 system header 没有 openat2。 如果你不需要用 openat2,可以将以下文件写到 `/usr/include/linux/openat2.h`: ```c /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ #ifndef _UAPI_LINUX_OPENAT2_H #define _UAPI_LINUX_OPENAT2_H #include /* * Arguments...

b8a218adb245ce07ec64ee62037ed5a8335edb94 兼容性更新:现在支持在没有``的环境下编译了!

计算密集型和 IO 密集型任务混合几乎没有性能损失,因为每个线程的 CPU 总是 100% 利用率,而且没有空转 (busy loop)。 针对你的场景,我推荐将加密和HTTP任务**安排到不同的 `io_context`**。在实现上,一个 `io_context` 对应一个线程,恰好能对应上你的 A/B 线程模型。 在 A/B `io_context` 之间用 `channel` 通信即可,这里有一个例子:[channel.cpp](https://github.com/Codesire-Deng/co_context/blob/main/example/channel.cpp) 需要提示的是,在有多个 `io_context` 的场景下,它们是不会自动结束的,这是为了防止线程间通信延迟造成信息丢失。如果实在需要 kill `io_context`,可以使用 `this_io_context().can_stop();`

> `co_context::mutex`和`co_context::condition_variable`是线程安全的吗?如果是的话,对于同一个线程的通信是不是这种同步开销是有害的? 是线程安全的,有原子变量读-改-写的开销。 > 是否可以提供一个同一线程内部的线程不安全的`co_context::condition_variable`? 可以。估计在 3 天内完成草稿。

如果跨 `io_context` 使用同步原语,确实需要用线程安全的版本。考虑到 x86 下单线程原子指令的开销很低,默认全用线程安全的 `mutex`, `condition_variable` 的开销通常可以接受。当然在 RISC-V 的表现如何,就是另一个话题了。 *论文我找找看吧* C++20 是看 [cppcoro](https://github.com/lewissbaker/cppcoro) 和 cppreference 硬啃的,当时资料不如现在丰富

文章裁剪之后可以公开:#94 ,请留意一年半以来,功能和性能已有不少变化和改进。

在协程的优势下,一些 callback 是可以省略的,通常的做法是将失败信息 co_return 给上层: ```cpp // Return true if successful. // Return false if timeout or any failure occurs. task SendRequest( co_context::socket socket, std::span buf, double time_ms ) {...