質問

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?

役に立ちましたか?

解決 2

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?

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.

To quote from the wikipedia definition:

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.

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.

Edit:

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:

他のヒント

The simple answer is: Wikipedia is wrong / inconsistent. Green threads can make use of M:N threading. Notably, this is how Erlang works. (I don't have a reference for this, but it shows up in most discussions of the VM.)

If you were being a language lawyer, then you could say that this doesn't happen "automatically". The green thread implementation has to take care of scheduling green threads on multiple native threads, instead of the operating system doing this implicitly. That said, the greater point remains, which is that it's very much possible for green threads to execute in parallel on a multicore system.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top