3 ms·
Coroutines can be divided into two categories, stackless and stackful. goroutines are stackful coroutines.
by surajrmal 3y ago
Coroutines can be divided into two categories, stackless and stackful. goroutines are stackful coroutines.
- jpc0 3y agoExcept goroutines will absolutely spawn a thread which a coroutine by definition wont. Goroutines are parallel, coroutine are concurrent. Those are not the same thing. Coroutines co-operatively yeild to other coroutines. Parallel constructs run in parallel at the same time. Goroutines can run in parallel at the same time and thus are not a coroutine.
- gpderetta 3y agoMy understanding is that goroutines don't spawn threads per-se. They can be executed on parallel event loops, but that can be true for stackess coroutines in c++ for example.
- jpc0 3y agoYeah goroutines are a pretty high level abstraction but they are definitely closer in concept to green threads than to coroutines. You can run a C++ coroutine on a seperate thread but you effectively need to build all the task handling logic yourself of use a library that's build that out. Goroutines you don't need to use a specialised sleep fuction which is actually changing coroutine state, setting a timer and yeilding. You just sleep as an example