2 ms·
A task is a future or a promise which can deliver a result later. A Goroutine in go is more general than a task because they don't have to terminate when they d
by jlouis 14y ago
A task is a future or a promise which can deliver a result later. A Goroutine in go is more general than a task because they don't have to terminate when they deliver a result. The subsume tasks in any way.
Goroutines are mapped onto (kernel-level) threads in order to make it possible to run more of them at once and thus provide parallel execution. Otherwise, you have a single scheduler of goroutines in a single process. You can still switch context between the goroutines, thus the system is concurrent. But it will not be parallel: One goroutine only at a time.
For a system in which most goroutines wait on IO or the network, it may not be a problem to run many goroutines on a single core only.
- magic_haze 14y agoI still don't quite follow. What do you mean by "terminate" a task? From my understanding, when a Task returned, the underlying Thread would be returned to the common pool for use by other Tasks. Does the Go scheduler detect when a task is blocked for IO, and reuse the thread for other goroutines?
- nivertech 14y ago"to make it possible to run more of them at once and thus provide parallel execution." I guess you meant "concurrent execution" here ;) "Otherwise, you have a single scheduler of goroutines in a single process. ... But it will not be parallel: One goroutine only at a time." So Go doesn't have something equivalent to SMP scheduler in Erlang?