2 ms·
I always considered "green threads" and "coroutines" to be the same thing? Are they not?
by quacker 6y ago
I always considered "green threads" and "coroutines" to be the same thing? Are they not?
- deleted 6y ago[deleted]
- infinite8s 6y agoThey are both built on the same technology in the CPython runtime.
- zenhack 6y agoThe difference is that with coroutines, yielding is explicit. Tight-looping will hog the CPU, and a blocking call will block other coroutines too. Typically "green threads" are semantically just threads but cheaper. They're scheduled independently, so there's no risk of them hogging the CPU, and you can use synchronous apis. The one downside is that you need explicit synchronization between them, whereas with coroutines you can mutate shared data structures and not worry about race conditions as long as you don't yield in between.