英文:
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<GoroutingStyle> t1;
std::thread<NativeThreadStyle> 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论