std::thread in C++ vs. goroutine in go language?

std::thread in C++ vs. goroutine in go language?

本文关键字:in language go goroutine C++ thread std vs      更新时间:2023-10-16

go语言中goroute的本质是自动光纤/协程。

C++ 中 std::thread 的本质是本机线程的包装器。

我认为 std::thread 应该是并行工作的抽象,而不仅仅是原生线程。在云计算时代,它非常重要。

有没有办法像下面这样使用 std::thread:

std::thread<GoroutingStyle>    t1;
std::thread<NativeThreadStyle> t2;

或者如果没有,C++标准是否考虑添加一些功能/库来支持goroutine?

或者如果没有,C++标准是否考虑添加一些功能/库来支持goroutine?

您请求的类似于光纤库 - 即将推出的库 boost.fiber 包含协作调度的光纤、互斥体/条件可值/屏障/... - 接口类似于 boost.thread。