V2EX  ›  英汉词典

Coroutine

释义 Definition

协程:一种用于并发/异步编程的程序结构。它把任务拆成可“暂停并稍后继续”的执行片段,多个协程可以在同一线程中协作式地轮流运行(常见于 await/yield 等机制),从而在不创建大量线程的情况下提高响应性与资源利用率。

发音 Pronunciation

/ˌkɔːrəˈtiːn/

例句 Examples

I used a coroutine to wait for two seconds without blocking the app.
我用协程等待两秒而不阻塞应用程序。

In the server, each client connection is handled by a coroutine that yields while waiting for network I/O, improving throughput under heavy load.
在服务器中,每个客户端连接由一个协程处理;它在等待网络 I/O 时让出执行权,从而在高负载下提升吞吐量。

词源 Etymology

coroutine 由前缀 co-(“共同、协作”)+ routine(“例程、程序段”)构成,字面意思是“共同运行的例程”。它强调多个程序段之间的协作式切换:不是被操作系统强制抢占,而是由协程在合适的时机主动暂停/恢复。

相关词 Related Words

文学与著作 Literary Works

  • Programming in Lua(Roberto Ierusalimschy):专章介绍 Lua 的 coroutines
  • Fluent Python(Luciano Ramalho):在生成器与异步章节中频繁讨论 coroutines
  • Python Cookbook(David Beazley, Brian K. Jones):在并发/异步相关示例中使用 coroutine 概念与写法。
  • *Structure and Interpretation of Computer Programs (SICP)*:在控制流与程序组织的讨论中提及/涉及 coroutines 思想。
关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   810 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 12ms · UTC 19:07 · PVG 03:07 · LAX 11:07 · JFK 14:07
♥ Do have faith in what you're doing.