From the course: Applied Concurrency in Go
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
Goroutines basics - Go Tutorial
From the course: Applied Concurrency in Go
Goroutines basics
- [Instructor] The definitions of concurrency and parallelism are universal, but Go deals with concurrency in a particularly elegant way. One of the pillars of concurrency in Go is the humble Goroutine. Goroutines are independently executing functions, which run on a set of threads. There are sometimes referred to as lightweight threads, but they are in fact, a level of abstraction on top of threads. The go runtime schedules goroutines and runs them in an optimal way on top of threads. The number of Goroutines usually outnumbers the threads by orders of magnitude. The Go runtime, not us, chooses when the Goroutines are run. Relating back to our traffic analogy, we can imagine the cars as our Goroutines or independently running tasks. The road as the threads they are running on. And the Go runtime as the traffic controller, optimally directing traffic. Let's have a look at a typical hello world example. Can't have a…