I'm currently reading the slices of Go Concurrency Patterns. I'm a little bit confused about a seeming contradiction between a statement on slide #16:
When main returns, the program exits and takes the boring function down with it.
and another one on slide #19 (in combination with the example on slide #20):
A channel in Go provides a connection between two goroutines, allowing them to communicate.
If main
is just a goroutine, how can it cause any another (spawned) goroutine to stop, in other words: in what sense is the goroutine named main
special?*
* I searched for it, but found nothing obviously enlightening so far; the SO question with the promising title Difference between the main goroutine and spawned goroutines of a Go program asks for a completely different issue.
edit: changed the title, to focus on the difference between main and "normal" goroutines (after stumbling upon the Go runtime function Goexit)
edit: simplified question, to be even more focused on the specifics of main