Golang (Go) is renowned for its straightforward and effective approach to concurrent programming. One of its guiding philosophies is the phrase: “Do not communicate by sharing memory; instead, share memory by communicating.” To truly understand the essence of this philosophy, let’s explore it using Golang examples that illustrate it.
Traditional Approach in Go: Mutex Locks and Shared Memory
Even though Go provides modern concurrency primitives like channels, it still allows for the use of mutex locks for those who prefer a more traditional approach to concurrency. Below the diagram of the sample code that we present right after it.

Example: Summing Numbers Concurrently
Let’s consider a simple task: summing an array of numbers. We can divide this task among multiple Goroutines and have each one sum part of the array. We could use a shared variable to accumulate the total sum, making sure to lock it before each update.