4 ms·
>Native threads are much faster at context switching then green threads No, native threads have a much higher context switch overhead. The downside of green t
by imanaccount247 12y ago
>Native threads are much faster at context switching then green threads
No, native threads have a much higher context switch overhead. The downside of green threads is the lack of parallelism, you can only use one CPU core. This is why decent languages multiplex green threads over OS threads (M:N). The mistake rust made was trying to make that distinction transparent.
- lgunsch 12y agoQuote from Wikipedia article on Green Threads: "Linux native threads have slightly better performance on I/O and context switching operations." Some of the actual context switch in native threads is performed by the CPU, where as with green threads it is not. On top of this, the whole stack is copied upon a context switch.
- ptx 12y agoThe paper[1] cited for that quote is specifically about PersonalJava 1.1.3 on Linux 2.2 on PowerPC. It may not be relevant to implementations from this century. [1] http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.8.9238&rep=rep1&type=pdf http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.8.9...
- imanaccount247 12y agoYour quote lacks the context which makes it clear that it is not a general claim. >Some of the actual context switch in native threads is performed by the CPU, where as with green threads it is not Exactly. Native threads have a context switch, green threads don't.
- SamReidHughes 12y agoWikipedia is wrong and generally speaking you shouldn't trust it on CS matters. Or any other subject, really. Green thread context switching is much faster than native thread switching, as long as you don't do it badly. For example, on Linux, don't use setcontext/swapcontext/etc, because they do a system call to change the signal mask.
- SamReidHughes 12y agoGreen threads also suck for other reasons. Async file I/O doesn't really work properly on Linux or OS X, so you have to use a thread pool for that, and you can't casually use any other library you'd otherwise want to use, either.
- imanaccount247 12y agoThat's why a decent language multiplexes green threads over native threads so you can have your cake and eat it too. You still need the ability to choose to create a green thread or a native thread though, it is the idea of trying to make the two interchangeable that was a problem.
- mietek 12y agoWhich languages multiplex green threads over OS threads in a non-transparent fashion, exactly?