In Go, a simple lock is a pointer to a mutex struct type, which belongs to the sync package. We can create a mutex as follows:
var myMutex = &sync.Mutex{}
Let's assume that we have a map called myMap of the map[int]inttype that we'd like to protect from the concurrent access of multiple goroutines:
myMutex.Lock() myMap[1] = 100 myMutex.Unlock()
If we ensure that all goroutines that need to edit myMap have access to myMutex, we can protect myMap against multiple goroutines changing it at the same time.