5 Condition variables and semaphores
This chapter covers
- Waiting on conditions with condition variables
- Implementing a write-preferring readers–writer lock
- Storing signals with counting semaphores
In the previous chapter, we saw how we can use mutexes to protect critical sections of our code and prevent multiple goroutines from executing at the same time. Mutexes are not the only synchronization tool that we have available: condition variables give us extra controls that complement exclusive locking. They give us the ability to wait for a certain condition to occur before unblocking the execution. Semaphores go one step further than mutexes in that they allow us to control how many concurrent goroutines can execute a certain section at the ...
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.