-
Book Overview & Buying
-
Table Of Contents
Practical Systems Programming in Go
By :
Everything in Go is executed as a goroutine, either transparently or intentionally. To create a new goroutine, we use the go keyword followed by a function call or an anonymous function – the two methods are equivalent. Each executable Go program has at least one goroutine, which is used for running the main() function of the main package. For a goroutine or a function to terminate the entire Go application, it should call os.Exit() instead of return. However, most of the time, we exit a goroutine or a function using return because what we really want is to exit that specific goroutine or function and not stop the entire application. Each goroutine is executed on a single OS thread according to the instructions of the Go scheduler, which is responsible for the execution of goroutines – the developer has no control over the amount of memory allocated to a goroutine.
The Go runtime scheduler, rather than the OS, manages the creation of threads. It...