Concurrency mechanisms in Go
Go’s in-built concurrency mechanisms are one of its biggest strengths and are often one of the main reasons developers choose to use Go for their services. Implementing concurrency in Go is easy (and painless!) due to its goroutines and channels. In this section, we will explore each mechanism and review its behavior so that we can better understand how to use and test them.
Concurrency is a program’s ability to process multiple tasks at the same time. This crucial ability allows us to get the most out of the CPU processing power, allowing us to make optimal use of our resources. This is important in all systems in order to be able to process as many requests as possible, without disrupting other flows in the program and keep computing costs low.
Figure 9.1 depicts two concurrent tasks:
Figure 9.1 – Concurrent execution flow of two tasks
The tasks are divided into functions that form a call stack:
...