We saw how channels are focused on communication between goroutines, and now we will focus on the tools offered by the sync package, which includes the basic primitives for synchronization between goroutines. The first thing we will see is how to implement concurrent access to the same resource with lockers.
Synchronization primitives
Concurrent access and lockers
Go offers a generic interface for objects that can be locked and unlocked. Locking an object means taking control over it while unlocking releases it for others to use. This interface exposes a method for each operation. The following is an example of this in code:
type Locker interface {
Lock()
Unlock()
}