This preview shows page 1. Sign up to view the full content.
Unformatted text preview: fer to be empty with a È operation on semaphore empty. After the producer writes the item to the buffer, it informs the consumer that there is now a valid item with a Î operation on full. Conversely, the consumer thread waits for a valid item with a È operation on full. After reading the item, it signals that the buffer is empty with a Î operation on empty. The impact at run-time is that the producer and consumer ping-pong back and forth, as shown in Figure 11.21. 11.5 Synchronizing Threads with Mutex and Condition Variables
As an alternative to È and Î operations on semaphores, Pthreads provides a family of synchronization operations on mutex and condition variables. In general, we prefer semaphores over their Pthreads counterparts because they are more elegant and simpler to reason about. However, there are some useful synchronization patterns, such as timeout waiting, that are impossible to implement with semaphores. Thus, it is worthwhile to have some facility with the Pthreads operations. I...
View Full Document