3 ms·
> First, context-switching in coroutines is at least a thousand times faster than with threads. You misunderstand how context switching works. It doesn't matte
by otabdeveloper2 8y ago
> First, context-switching in coroutines is at least a thousand times faster than with threads.
You misunderstand how context switching works. It doesn't matter how many threads you have -- 5 or 5000. Your OS will switch contexts at a constant rate.
What you perceive as 'context switch overhead' is really process scheduling being too smart for its own good.
99% of the time the problem is solved with a simple round-robin process scheduler. (Called a 'realtime' scheduler in Linux.)
> it is common to see multithreaded applications spending more CPU time on context-switching than actually running application code
No. Like I said, context switching is constant-time overhead for your OS.