过程,线程,绿色线程,原线程,纤维,协程:有什么区别? [英] Processes, threads, green threads, protothreads, fibers, coroutines: what's the difference?
问题描述
我正在读并发。我有一个有点在我的头有一些令人困惑的类似定义的术语。即:
- 处理
- 主题
- 线程
- 我的印象是,区别在于(1)是真正的并行还是多路复用; (2)是否在CPU,OS或程序中管理;
有关这些并行方法之间的区别的简明和明确的指南吗? p>
解决方案好的,我要尽我所能。在任何地方都有警告,但我会尽我所能让我理解这些术语,并引用一些与我给出的定义近似的东西。
- 流程:操作系统管理(可能)真正并发,至少在合适的硬件支持的存在下。
- 主题 a>:OS管理,在与父级和所有其他线程相同的地址空间中。可能是真正的并发,多任务是先发制人。
- 绿色线程:这些是与线程相同的概念的用户空间投影,但不是操作系统管理。可能不是真正的并发,除非在可能有多个工作线程或进程同时给它们CPU时间,所以最好考虑这是交织或复用。
- Protothreads :我不能真正地挑逗出这些定义。我认为他们是交错和程序管理,但不要接受我的话。我的意思是,他们本质上是一个应用程序特定的实现相同类型的绿线程模型,适当修改应用程序域。
- 光纤:操作系统管理。
- Goroutines :他们声称不同于别的东西,但他们似乎是完全绿色的线程,如在过程管理在一个单一的地址空间和复用到系统线程。
还有一点值得注意的是,对于并发还有其他的理解。 >过程计算术语过程中的理论。这个定义与上面的定义是正交的,但我只是认为它值得一提,所以如果你看到在某种意义上使用的进程,不会产生混淆。
并行和 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屋!