标签:切换 which python edit component eval hand parallel ide
关键词:协程 栈帧 指令 切换 跳转
异步结果的等待、后继计算的保存。
Coroutines are computer program components that generalize subroutines for non-preemptive multitasking, by allowing execution to be suspended and resumed. Coroutines are well-suited for implementing familiar program components such as cooperative tasks, exceptions, event loops, iterators, infinite lists and pipes.
Python 3.5 introduces explicit support for coroutines with async/await syntax
Comparison with threads[edit]
Coroutines are very similar to threads. However, coroutines are cooperatively multitasked, whereas threads are typically preemptively multitasked. This means that coroutines provide concurrency but not parallelism. T
var q := new queue
coroutine produce
loop
while q is not full
create some new items
add the items to q
yield to consume
coroutine consume
loop
while q is not empty
remove some items from q
use the items
yield to produce
Implementations for C[edit]
In order to implement general-purpose coroutines, a second call stack must be obtained, which is a feature not directly supported by the C language.
Implementations for Rust[edit]
There is a library for Rust that provides coroutines.[45] Generators are an experimental feature available in nightly rust that provides an implementation of coroutines with async/await.[46]
标签:切换 which python edit component eval hand parallel ide
原文地址:https://www.cnblogs.com/feng9exe/p/10479161.html