3 ms·
>You can use coroutines to implement generators Yes, and threads as well, so back to my original question.
by ur-whale 8y ago
>You can use coroutines to implement generators
Yes, and threads as well, so back to my original question.
- amelius 8y agoThe use of generators does not imply concurrency, and that's why the use of threads for this purpose is considered overkill (threads require relatively expensive kernel involvement).
- rurban 8y agoThe main difference is the low speed of threads (100 slower context switches) and the problems of parallelism: deadlocks, races. Thats why you use threads for CPU bound tasks, and coros for IO bound tasks. With IO you don't need much CPU, you mostly wait. Coros provide fast switching back and forth until your IO is ready.