|
|
|
|
|
by YZF
1479 days ago
|
|
There is a ton of context associated with OS/kernel threads. Virtual memory, security, I/O. While there is some hardware acceleration for those in modern processors there isn't anything like LOAD THREAD and even with CPU support it's still very expensive. You get an interrupt, then the kernel needs to load its own context (the tables it needs to access), then the kernel needs to do the expensive switch. In user space you have a lot less context. The actual switching is pretty much the cost of a function call. If you need preemption that's a different story and mostly depends on what facilities are available for that. Inserting preemption checks is a little hacky (hello Go ;) ) but what can you do. EDIT: It's worthwhile noting there's indirect costs like caches being stale. Lightweight/green threads will often work on shared data structures so the caches are more likely to have something useful in them. They may even share the code. |
|