4 Synchronization with mutexes
This chapter covers
- Protecting critical sections with mutex locks
- Improving performance with readers–writer locks
- Implementing a read-preferred readers–writer lock
We can protect critical sections of our code with mutexes so that only one goroutine at a time accesses a shared resource. In this way, we eliminate race conditions. Variations on mutexes, sometimes called locks, are used in every language that supports concurrent programming. In this chapter, we’ll start by looking at the functionality that mutexes provide. Then we’ll look at a variation on mutexes called readers–writer mutexes.
Readers–writer mutexes give us performance optimizations in situations where we need to block concurrency only when modifying ...
Get Learn Concurrent Programming with Go now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.