Goroutines
Up until this point, we have been referring to concurrent paths of execution as threads. In Go, the synonymous tool for accomplishing this is called a goroutine. Goroutines are described as a:
Lightweight thread of execution.
Unlike traditional threads found in C and Java, goroutines are managed by the Go runtime and not the OS thread scheduler. This allows the Go runtime scheduler to be hyper-focused on only tasks in the Go program. It also leverages OS threads as needed, providing more granular units of operation. OS threads suffer from a large amount of overhead required to create each thread and a relatively slow ability to determine which thread a task should be run on. The Go runtime chooses much smaller footprints when creating ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access