Mutex

Learn about mutexes and their implementation in Golang.

What is mutex?

Let’s assume that we want a piece of code to be accessible by only one goroutine at a time. We’ll need to have a locking and unlocking mechanism that can be enabled and implemented using a mutex.

We can lock and unlock a block of code with a mutex. The section locked inside a mutex is a critical section. Mutexes can also be used to protect caches, states, and registers from concurrent access.

Get hands-on with 1200+ tech skills courses.