gpt4 book ai didi

c++ - suspend-up 和 suspend-down 协程有什么区别?

转载 作者:搜寻专家 更新时间:2023-10-31 01:27:32 27 4
gpt4 key购买 nike

C++ 社区目前正在讨论上挂协程与下挂协程。

例如,这个提案中提到了挂起:http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4453.pdf

这两个词是什么意思?

最佳答案

术语似乎在 p0099r1: "A low-level API for stackful context switching" 中有解释。其中说:

Notes on suspend-up and suspend-down terminology The terms suspend-upand suspend-down were introduced in paper N4232 2 and carried forwardin P0158 9 to distinguish stackless ( suspend-up ) and stackful (suspend-down ) context switching. These terms rely on a particularvisualization of the C++ function call operation in which calling afunction passes control “downwards,” whereas returning from a functionpasses control “upwards.” The authors recommend the termssuspend-by-return instead of suspend-up , and suspend-by-call insteadof
suspend-down . The recommended terminology directly references theunderlying C++ operations, without requiring a particularvisualization.
suspend-by-return ( suspend-up , or “stackless” contextswitching) is based on returning control from a called function to itscaller, along with some indication as to whether the called functionhas completed and is returning a result or is merely suspending andexpects to be called again. The called function’s body is coded insuch a way that – if it suspended – calling it again will directcontrol to the point from which it last returned. This describes bothP0057 6 resumable functions and earlier technologies such asBoost.Asio coroutines. 12
suspend-by-call ( suspend-down, or“stackful” context switching) is based on calling a function which,transpar- ently to its caller, switches to some other logical chain offunction activation records. (This may or may not be a contiguousstack area. The processor’s stack pointer register, if any, may or maynot be involved.) This describes N4397 3 coroutines as well asBoost.Context, 13 Boost.Coroutine2 14 and Boost.Fiber. 15std::execution_context<>::operator()() requires suspend-by-callsemantics.

都是旧论文,与p0057分开这似乎是主要的协程文件。 p0444 讨论了试图统一这些文件,但似乎没有任何进展。另见 Trip Report: C++ Standards Meeting in Issaquah, November 2016其中说:

The Coroutines TS contains the co_await proposal, based on Microsoft’s original design.

As mentioned previously, there are efforts underway to standardize a proposal for a different, stackful flavour of coroutines, as well as an exploratory effort to unify the two flavours under a common syntax. These proposals, however, are not currently slated to target the Coroutines TS. They may instead target a different TS (and if a unified syntax emerges, it could be that syntax, rather than the one in the Coroutines TS, that’s ultimately merged into the C++ standard).

关于c++ - suspend-up 和 suspend-down 协程有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53291812/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com