与提升。c++的纤程是否更接近Erlang风格的进程/线程?

时间:2020-12-11 21:00:45

I am reading http://olk.github.io/libs/fiber/doc/html/ It seems to me that with Boost.Fiber C++ is coming closer to Erlang's ability to have thousands of "processes", also known as "green processes[threads]" http://en.wikipedia.org/wiki/Green_threads.

我正在读http://olk.github。io/libs/fiber/doc/html/在我看来是Boost。光纤c++正越来越接近Erlang拥有数千个“进程”的能力,也被称为“绿色进程[线程]”http://en.wikipedia.org/wiki/Green_threads。

My question is, is Boost.Fiber ready for production, are there now c++ alternatives that have better documentation and examples? Someone mentioned lightweight threads, but I can't seem to find a reference to it. One final question is, why doesn't the C++ standard include Fibers?

我的问题是,是Boost。光纤已经准备好生产了,现在有更好的文档和示例的c++替代品吗?有人提到了轻量级线程,但我似乎找不到它的引用。最后一个问题是,为什么c++标准不包括纤维?

The reason I am interested in this is because I have realtime updates where a value change can impact (spawn) hundreds/thousans of small but embarrassingly parallel computations. The C++ thread model doesn't work very well, imo. Please no GPU, since it currently takes too long to transfer the information to and from the GPU.

我对此感兴趣的原因是,我有实时更新,值更改可能会影响(生成)成百上千的小型但令人尴尬的并行计算。在我看来,c++线程模型不太好用。请不要使用GPU,因为目前GPU与GPU之间的信息传递时间太长。

I realize that Erlang is far more than this so please don't educate me on Erlang vs C++ in the general case.

我知道Erlang远不止这些,所以请不要在一般情况下教我Erlang vs c++。

1 个解决方案

#1


13  

Boost.Fiber was reviewed by the Boost community in January 2014 and was found to need significant additional work. See the results of the community review at http://lists.boost.org/boost-announce/2014/01/0393.php.

提振。Boost社区在2014年1月对光纤进行了评估,发现需要大量的额外工作。参见http://lists.boost.org/boost-announce/2014/01/0393.php的社区评审结果。

C++ 17 also looks to gain a WinRT like M:N threading model based around resumable functions using the proposed await keyword. Microsoft have implemented support in their compiler, and apart from magic memory allocation tricks for futures it looks very promising. The relevant N paper is N4134 (http://www.open-std.org/Jtc1/sc22/wg21/docs/papers/2014/n4134.pdf), and as you will see that if accepted, this formulation of resumable functions would indeed provide Erlang type scalability even if the syntax is a bit obtuse (hey, it's C++, when is its syntax ever straightforward!).

c++ 17还希望获得一个类似于M:N线程模型的WinRT模型,该模型基于可恢复的函数,使用建议的wait关键字。微软已经在他们的编译器中实现了支持,除了神奇的内存分配技巧外,它看起来很有前途。相关的N篇论文是N4134 (http://www.open-std.org/Jtc1/sc22/wg21/docs/papers/2014/n4134.pdf),正如您将看到的那样,如果被接受,这种可恢复函数的形式确实可以提供Erlang类型的可扩展性,即使语法有点晦涩(嘿,它的语法很简单,什么时候)!

Of course, if you need a portable solution now, either go the stackless coroutine route with ASIO (caution: it's brittle), or finely grain ASIO handlers with ASIO strands using a class instance as your execution state which is much the same thing, or else use Boost.Fiber anyway. If you only need Windows, I'd press ahead with Microsoft's proprietary extensions myself, they are highly unlike to abandon them unless they abandon WinRT :)

当然,如果您现在需要一个可移植的解决方案,您可以使用ASIO(注意:它很脆弱)来执行stackless coroutine路线,或者使用ASIO链使用类实例作为执行状态,或者使用Boost。纤维。如果你只需要Windows操作系统,我也会继续使用微软的专有扩展,除非他们放弃WinRT:)

Edit: The author of Boost.Fiber tells me that as of January 2015 the recommended changes from the community review are complete, and apart from documentation improvements Fiber is considered ready for inclusion into official Boost. If this is indeed the case, then Fiber is probably the best solution before official C++ 17 language support for final resumable functions appears in compilers.

编辑:Boost的作者。Fiber告诉我,从2015年1月起,社区评审中推荐的更改已经完成,除了文档改进外,光纤被认为已经准备好纳入官方的Boost中。如果确实如此,那么在编译器中出现正式的c++ 17语言支持最终可恢复函数之前,Fiber是最好的解决方案。

#1


13  

Boost.Fiber was reviewed by the Boost community in January 2014 and was found to need significant additional work. See the results of the community review at http://lists.boost.org/boost-announce/2014/01/0393.php.

提振。Boost社区在2014年1月对光纤进行了评估,发现需要大量的额外工作。参见http://lists.boost.org/boost-announce/2014/01/0393.php的社区评审结果。

C++ 17 also looks to gain a WinRT like M:N threading model based around resumable functions using the proposed await keyword. Microsoft have implemented support in their compiler, and apart from magic memory allocation tricks for futures it looks very promising. The relevant N paper is N4134 (http://www.open-std.org/Jtc1/sc22/wg21/docs/papers/2014/n4134.pdf), and as you will see that if accepted, this formulation of resumable functions would indeed provide Erlang type scalability even if the syntax is a bit obtuse (hey, it's C++, when is its syntax ever straightforward!).

c++ 17还希望获得一个类似于M:N线程模型的WinRT模型,该模型基于可恢复的函数,使用建议的wait关键字。微软已经在他们的编译器中实现了支持,除了神奇的内存分配技巧外,它看起来很有前途。相关的N篇论文是N4134 (http://www.open-std.org/Jtc1/sc22/wg21/docs/papers/2014/n4134.pdf),正如您将看到的那样,如果被接受,这种可恢复函数的形式确实可以提供Erlang类型的可扩展性,即使语法有点晦涩(嘿,它的语法很简单,什么时候)!

Of course, if you need a portable solution now, either go the stackless coroutine route with ASIO (caution: it's brittle), or finely grain ASIO handlers with ASIO strands using a class instance as your execution state which is much the same thing, or else use Boost.Fiber anyway. If you only need Windows, I'd press ahead with Microsoft's proprietary extensions myself, they are highly unlike to abandon them unless they abandon WinRT :)

当然,如果您现在需要一个可移植的解决方案,您可以使用ASIO(注意:它很脆弱)来执行stackless coroutine路线,或者使用ASIO链使用类实例作为执行状态,或者使用Boost。纤维。如果你只需要Windows操作系统,我也会继续使用微软的专有扩展,除非他们放弃WinRT:)

Edit: The author of Boost.Fiber tells me that as of January 2015 the recommended changes from the community review are complete, and apart from documentation improvements Fiber is considered ready for inclusion into official Boost. If this is indeed the case, then Fiber is probably the best solution before official C++ 17 language support for final resumable functions appears in compilers.

编辑:Boost的作者。Fiber告诉我,从2015年1月起,社区评审中推荐的更改已经完成,除了文档改进外,光纤被认为已经准备好纳入官方的Boost中。如果确实如此,那么在编译器中出现正式的c++ 17语言支持最终可恢复函数之前,Fiber是最好的解决方案。