In this chapter, we will look at more synchronization patterns. We will start with a detailed look at bounded buffers. We will look at different design approaches, such as client-throwing exceptions and polling. We will see how to make the writer sleep when the buffer is full (and how to make the reader sleep when the buffer is empty), and this makes for an elegant client contract.
We will also look at readers or writers lock, a primitive synchronization to allow either multiple concurrent readers or a single writer. The idea is to increase the system's concurrency with correctly preserved concurrency semantics. We will look at two variations—reader-friendly locks and fair locks.
Next, we will discuss counting semaphores; these are used for implementing resource pooling. We will see how easily...