What is Mutex ?
Sukma Rizki
Posted on March 4, 2024
Before using mutex? It's a good idea for you to learn about race conditions, because these two concepts are closely related to each other.
A race condition is a condition where more than one goroutine accesses data together at the same time. When this happens, the data value becomes chaotic. In concurency programming this value often occurs.
Mutex changes the access level of data to executive, making the data only able to be consumed (read/written) by one goroutine. When a race condition occurs, the goroutine is lucky enough to be able to access the data. Other goroutines (whose running time happens to be the same) will be forced to wait, until the wait for using the data is complete.
Go provides sync.Mutex which can be used to lock and unclock data
Posted on March 4, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.