3 ms·
A very good question. For a green thread implementation as featureful as a platform thread, there is no fundamental reason they can not be made almost equivale
by Veserv 3y ago
A very good question.
For a green thread implementation as featureful as a platform thread, there is no fundamental reason they can not be made almost equivalent (there are a few minor hardware overhead limitations performance wise, but they are fairly negligible). But, in practice, platform threads on most kernels have large amounts of overhead that increase their cost beyond what would be theoretically necessary, so the benefits of green threads are overstated.
However, one major advantage of green threads is that they do not need to be as featureful as platform threads. You can remove features so it fits your exact needs on a per program basis instead of having a one size does all implementation.
For instance, you could use a smaller stack size. On most operating systems, they require stacks to be a multiple of the memory mapping size to allow more robust stack guards. You can get away with tiny stacks on a green thread if it works for the program.
If you know for certain that you will not use certain registers on a green thread you can reduce the size of the task control block to omit the registers.
You can choose a simpler scheduler amongst the green threads. This turns out to be the source of very significant improvements. Task scheduling code is actually the vast majority of context switch time, not hardware costs like most people believe.