Concurrency in Go (Golang) (9 – 2020) Free Tutorial Download
Rob Pike, One of the creators of Go in his 2012 Google I/O talk referred to concurrency as the composition of independently executing computations. Concurrency not to be confused with parallelism is a scenario whereby different computational tasks are executed in overlapping periods, in an out of order fashion that doesn’t affect the overall result of the program! Goroutines and channels are core components of concurrency in Go. This article aims to show how to use Goroutines and channels to write concurrent Go programs.
To follow along with this article you’ll need:
- Go installed on your computer.Depending on your os you can follow the following articles to get started with it Mac, Windows,Ubuntu
- Knowledge of how to convert data types in Go, You can follow this article to know more
- To know how to construct for loops in Go.
Goroutines can be thought of as lightweight,user-space threads that are managed by the Go runtime, Once a new goroutine is created, it gets its own call stack, the go runtime allocates a few flexible kilobytes to it which can increase and decrease in size according to its needs, this prevents excess memory usage and accounts for the lightweight nature of goroutines. They are functions executing concurrently with other goroutines in the same address space. The purpose of a goroutine is to have several independent functions executing at the same time incorporated onto a thread or set of threads such that once the execution of one function stops or is blocked due to a blocking operation like a network request the execution of the other functions wouldn’t stop! Instead, they would be moved to a different thread on the operating system to ensure that there is no pause in the execution of these functions! This task of scheduling various goroutines, moving them to available OS threads when there is a blocking operation is carried out by the Go-runtime scheduler. Goroutines are very cheap and require little system resources that is why it is possible to have several hundreds of goroutines in your programs, In the next section we will be going ahead to see how we are going to write some code and see how we can get started using goroutines in our programs.
Download Concurrency in Go (Golang) (9 – 2020) Free