3 ms·
Coroutines and threads are not that different. Threads usually preallocate some stack space, while coroutines usually don't. But that isn't such a big deal.
by otabdeveloper4 4y ago
Coroutines and threads are not that different.
Threads usually preallocate some stack space, while coroutines usually don't. But that isn't such a big deal.
- naasking 4y agoThat's not the only difference. Coroutines also typically don't have nearly as many concurrency hazards because you can control when you yield.
- dymk 4y agocoroutines can be either cooperative or not, depending on implementation, so it depends
- gpderetta 4y agoAnd so can threads.
- otabdeveloper4 4y agoThat's an implementation detail. Pthreads work differently, but historically kernel-mode cooperative threads were also popular at one time. (We decided to not go there because cooperative parallelism sucks balls.)
- josephg 4y agoCoroutines also don’t need to flush the TLB when they get scheduled. This is a pretty big deal for performance, when you have a lot of them.
- jlokier 4y agoThread context switches don't flush the TLB either. This is an important performance optimisation in the kernel context switch code.