Member-only story

Go Routines from Beginner to Expert

Marcus Man
3 min readSep 29, 2020

--

What are Gorountines and Threads?

// Evaluation happens in the current go routine
// Execution happens in a new go routine
go f(x, y, z)

A goroutine is a lightweight thread managed by the Go runtime, and a thread is the smallest unit of processing that can be performed in operating systems. Besides, a thread exists within a process, it means that a single process may contain multiple threads at the same time.

For example, a web server is designed to handle a bunch of independent requests at once, so threads can be created, or taken from a thread pool in order to achieve concurrency.

Goroutines is how golang handling tasks in a concurrent way. They exist only in the virtual space of the Go runtime and not the OS, therefore the Go Runtime scheduler is needed to manage their lifecycles.

Diagram of relationship between the runtime, OS and developer Go Code

What are Concurrency and Parallelism?

“Concurrency is about dealing with bunch of things at once. Parallelism is about doing lots of things at once.” — Rob Pike

Diagram of differences between concurrency and parallelism

--

--

No responses yet