过程,线程,绿色线程,原线程,纤维,协程:有什么区别? [英] Processes, threads, green threads, protothreads, fibers, coroutines: what's the difference?

查看:513
本文介绍了过程,线程,绿色线程,原线程,纤维,协程:有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在读并发。我有一个有点在我的头有一些令人困惑的类似定义的术语。即:




  • 处理

  • 主题

  • 线程



  • 我的印象是,区别在于(1)是真正的并行还是多路复用; (2)是否在CPU,OS或程序中管理;



    有关这些并行方法之间的区别的简明和明确的指南吗? p>

    解决方案

    好的,我要尽我所能。在任何地方都有警告,但我会尽我所能让我理解这些术语,并引用一些与我给出的定义近似的东西。





    还有一点值得注意的是,对于并发还有其他的理解。 >过程计算术语过程中的理论。这个定义与上面的定义是正交的,但我只是认为它值得一提,所以如果你看到在某种意义上使用的进程,不会产生混淆。



    并行 concurrent 。这可能是你在你的问题中使用前者,我认为你的意思是后者。


    I'm reading up on concurrency. I've got a bit over my head with terms that have confusingly similar definitions. Namely:

    • Processes
    • Threads
    • "Green threads"
    • Protothreads
    • Fibers
    • Coroutines
    • "Goroutines" in the Go language

    My impression is that the distinctions rest on (1) whether truly parallel or multiplexed; (2) whether managed at the CPU, at the OS, or in the program; and (3..5) a few other things I can't identify.

    Is there a succinct and unambiguous guide to the differences between these approaches to parallelism?

    解决方案

    OK, I'm going to do my best. There are caveats everywhere, but I'm going to do my best to give my understanding of these terms and references to something that approximates the definition I've given.

    • Process: OS-managed (possibly) truly concurrent, at least in the presence of suitable hardware support. Exist within their own address space.
    • Thread: OS-managed, within the same address space as the parent and all its other threads. Possibly truly concurrent, and multi-tasking is pre-emptive.
    • Green Thread: These are user-space projections of the same concept as threads, but are not OS-managed. Probably not truly concurrent, except in the sense that there may be multiple worker threads or processes giving them CPU time concurrently, so probably best to consider this as interleaved or multiplexed.
    • Protothreads: I couldn't really tease a definition out of these. I think they are interleaved and program-managed, but don't take my word for it. My sense was that they are essentially an application-specific implementation of the same kind of "green threads" model, with appropriate modification for the application domain.
    • Fibers: OS-managed. Exactly threads, except co-operatively multitasking, and hence not truly concurrent.
    • Coroutines: Exactly fibers, except not OS-managed.
    • Goroutines: They claim to be unlike anything else, but they seem to be exactly green threads, as in, process-managed in a single address space and multiplexed onto system threads. Perhaps somebody with more knowledge of Go can cut through the marketing material.

    It's also worth noting that there are other understandings in concurrency theory of the term "process", in the process calculus sense. This definition is orthogonal to those above, but I just thought it worth mentioning so that no confusion arises should you see process used in that sense somewhere.

    Also, be aware of the difference between parallel and concurrent. It's possible you were using the former in your question where I think you meant the latter.

    这篇关于过程,线程,绿色线程,原线程,纤维,协程:有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆