为什么绿色线程不能在多个内核上工作 [英] why green threads do not work on multiple cores

查看:126
本文介绍了为什么绿色线程不能在多个内核上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在维基百科上: Green_threads 被描述为通常无法在多核上运行而无需解释原因.

On wikipedia: Green_threads is described as normally cannot run on multi-cores without explaining why.

在多核处理器上,本机线程实现可以 自动将工作分配给多个处理器,而绿色线程 实现通常无法实现.

On a multi-core processor, native thread implementations can automatically assign work to multiple processors, whereas green thread implementations normally cannot.

我知道操作系统可以将本机线程分配给多核.有人可以解释为什么绿色线程不能在多核上运行吗?是因为绿色线程是从本地线程派生/衍生的,所以它们不能从本地线程移到另一个?

I understand native threads can be assigned by OS to multi-cores. Can someone explain that why green threads can not run on multi-cores? Is it because green threads are derived/spawned from native threads, they cannot be moved from on native thread to another?

推荐答案

我知道操作系统可以将本机线程分配给多核.有人可以解释为什么绿色线程不能在多核上运行吗?

I understand native threads can be assigned by OS to multi-cores. Can someone explain that why green threads can not run on multi-cores?

据我了解,绿色线程的重要目标之一是由软件/VM 完全控制它们,而无需操作系统干预.它是帮助正常"线程派生虚拟进程并在多个处理器上并行运行它们的操作系统.操作系统将多个绿色线程视为要在单个处理器上调度的单个线程.

It is my understanding that one of the important goals of green threads is that they are managed completely by the software/VM without operating system intervention. It is the OS that helps "normal" threads fork the virtual processes and run them in parallel on multiple processors. The operating system sees multiple green-threads as a single thread to be scheduled on a single processor.

引用维基百科定义:

绿色线程在不依赖任何本机OS功能的情况下模拟多线程环境,并且它们在用户空间而不是内核空间中进行管理,从而使它们可以在不具有本机线程支持的环境中工作.

Green threads emulate multithreaded environments without relying on any native OS capabilities, and they are managed in user space instead of kernel space, enabling them to work in environments that do not have native thread support.

在单个处理器中运行对绿线程有一些重要的好处,包括没有缓存的内存同步问题,更快的启动,更好的整体同步性能.其中大多数好处只有在相同的CPU上运行时才能实现.

Running in a single processor has some important benefits to green-threads including no cached memory synchronization issues, faster startup, better overall synchronization performance. Most of these benefits are only possible if they are running in the same CPU.

关于Erlang和其他语言在其绿色线程"实现中使用多个处理器的讨论很多.我会争辩说,即使该语言使用绿色"一词来形容它们,也违反了经典的定义.当然,这些术语变得混乱不堪,但是许多术语将Erlang的线程描述为绿色过程"以进行区分.它们绝对是轻量级的,但是即使有重叠但不同的实现,绿色线程"的概念和定义也不应更改.我还没有找到Erlang文档将其线程范式描述为绿色".

There have been lot of discussions about Erlang's and other languages use of multiple processors in their "green thread" implementations. I would argue that even if the word "green" is used by the language to describe these, they violate the classic definition. Certainly the terms are getting muddy but many are describing Erlang's threads as "green processes" to differentiate. They are definitely lightweight but the concepts and definition of "green threads" should not change even when there are overlapping but different implementations. I have yet to find the Erlang documentation describe their threading paradigm as "green".

下面有许多页面与此评估相符:

Here's a number of pages that agree with this assessment:

  • Native Vs Green Threads
  • Four for the Ages
  • Green Vs. Native Threads
  • What is the difference between "green" threads and "native" threads?

这篇关于为什么绿色线程不能在多个内核上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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