Thread(线程)、Fiber(纤程)、coroutine(协程) 之间的区别以及...

前天和同事聊到coroutine,有一些认知上的迷惑,搜索翻看了一些文章,出了下表(没表你xxx):

注:在通常意义下

分类 OS Schedule (multicore support) User Schedule (Language/Library)
Preemptive thread ?
Non-preemptive (cooperative) fiber coroutine

总结如下:
1. 关于process和thread的由来以及演化,脱不开计算机发展过程中,具体操作系统、语言和库的实际需求。而且由于名词的混用,在实际讨论时,也需要明确环境设定;
2. 有些名词可以认为是大家都认同的事物的定义(process、thread、fiber),有些名词是笼统的概念(Kernel/User Thread、Preemptive/Non-preemptive/Cooperative Thread),有些名词是库的名字(Green Thread),而有些名词是规范(POSIX thread -> pthread)


参考:
1. Threads, green threads, fibers, green fibers, pthreads, user threads, kernel threads, hyper threads, how the bloody hell do you make sense of the thread menagerie?
2. Processes, threads, green threads, protothreads, fibers, coroutines: what’s the difference?

你可能感兴趣的:(编程)