- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
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/
在我的设置中,我试图有一个界面 Table继承自 Map (因为它主要用作 map 的包装器)。两个类继承自 Table - 本地和全局。全局的将有一个可变的映射,而本地的将有一个只有本地条目的映射。
Rust Nomicon 有 an entire section on variance除了关于 Box 的这一小节,我或多或少地理解了这一点和 Vec在 T 上(共同)变体. Box and Vec
我是一名优秀的程序员,十分优秀!