Difference between a “coroutine” and a “thread”?

前端 未结 6 1776
再見小時候
再見小時候 2020-11-29 14:47

What are the differences between a \"coroutine\" and a \"thread\"?

6条回答
  •  南方客
    南方客 (楼主)
    2020-11-29 15:10

    Coroutines are a form of sequential processing: only one is executing at any given time (just like subroutines AKA procedures AKA functions -- they just pass the baton among each other more fluidly).

    Threads are (at least conceptually) a form of concurrent processing: multiple threads may be executing at any given time. (Traditionally, on single-CPU, single-core machines, that concurrency was simulated with some help from the OS -- nowadays, since so many machines are multi-CPU and/or multi-core, threads will de facto be executing simultaneously, not just "conceptually").

提交回复
热议问题