GOLANG

Anatomy of goroutines in Go -Concurrency in Go

goroutine is a lightweight execution thread running in the background. goroutines are key ingredients to achieve concurrency in Go.

Uday Hiwarale
RunGo
Published in
7 min readNov 4, 2018

--

In the previous lesson, we learned about Go’s concurrency model. As goroutines are lightweight compared to OS threads, it is very common for a Go application to have thousands of goroutines running concurrently. Concurrency can speed up application significantly as well as help us write code with separation of concerns (SoC).

☛ What is a goroutine?

We understood in theory that how goroutine works, but in code, what is it? Well, a goroutine is simply a function or method that is running in background concurrently with other goroutines. It’s not a function or method definition that determines if it is a goroutine, it is determined by how we call it.

Go provides a special keyword go to create a goroutine. When we call a function or a method with go prefix, that function or method executes in a goroutine. Let’s see a simple example.

--

--