The last topic we will cover in this chapter is the sync package. The sync package is what you will use when you absolutely need to create a lock-in Go. Even though we mentioned that Go prefers the use of channels to communicate data between goroutines, there are cases where a lock or a mutual exclusion object (mutex) is unavoidable. An example of a scenario where locks are utilized in Go's standard package is the http package, where a lock is used to protect the set of listeners to a particular http server object. This set of listeners can be accessed from numerous goroutines so that they get protected by a mutex.
The word mutex, in the world of computer programming, refers to an object that allows multiple threads to access the same resource (such as shared memory). Mutex is so named because it allows only one thread to access data at one time.
The workflow...