go go/book/learninggo

Advanced Concurrency Patterns | Learn Go
🌟 Gist of Go: Goroutines

Concurrency

What is Concurrency ?

The ability to break down a computer program or algorithm into individual parts, which can be executed independently.

The final outcome of a concurrent program is the same as that of a program that has been executed sequentially.
Using concurrency, we can achieve the same results in lesser time, thus increasing the overall performance and efficiency of our programs.

Concurrency vs Parallelism

‘Concurrency is when the execution of two or more pieces of code act as if they run at the same time. Parallelism is when they do run at the same time.

To have concurrency, you need to run code in an environment that can switch execution between different parts of your code when it is running. This is often implemented using things such as fibers, threads, and processes.

To have parallelism, you need hardware that can do two things at once. This might be multiple cores in a CPU, multiple CPUs in a computer, or multiple computers connected together.’
—David Thomas and Andrew Hunt, “The Pragmatic Programmer: your journey to mastery, 20th Anniversary Edition, 2nd Edition”

Quote

“Concurrency is about dealing with lots of things at once. Parallelism is about doing lots of things at once” - Rob Pike
[!video]- Go - Concurrency

Concurrency and parallelism are completely different concepts.

Concurrency is the task of running and managing multiple computations at the same time, while parallelism is the task of running multiple computations simultaneously.

 Go relies on a concurrency model called CSP (Communicating Sequential Processes).
 

Communicating Sequential Processes (CSP)

Here, processes are independent and they communicate by sharing channels between them.

Concurrency | Learn Go