C++中的std::thread与Go语言中的goroutine有何区别?

huangapple go评论93阅读模式
英文:

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

问题

在Go语言中,goroutine的本质是自动的纤程/协程。

在C++中,std::thread的本质是本地线程的封装。

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

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

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

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

英文:

The nature of gorouting in go language is an automatic fiber/coroutine.

The nature of std::thread in C++ is a wrapper of native threads.

I think std::thread should be an abstraction of parallel works, not just for native threads. In cloud computing era, it's very important.

Is there any way to use std::thread like the following:

std::thread&lt;GoroutingStyle&gt;    t1;
std::thread&lt;NativeThreadStyle&gt; t2;

Or if not, does the C++ standard consider to add some features/libraries to support goroutine?

答案1

得分: 1

你的要求类似于一个纤程库,即将推出的库boost.fiber包含了协作调度的纤程、互斥锁/条件变量/屏障等功能,接口与boost.thread类似。

英文:

> Or if not, does the C++ standard consider to add some features/libraries to support goroutine?

what you are requesting is something like a fiber library - the forthcoming library boost.fiber contains cooperatively scheduled fibers, mutexes/condition-vairables/barriers/... - the interface is similar to boost.thread.

huangapple
  • 本文由 发表于 2013年9月1日 19:21:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/18557916.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定