CS 321 Spring 2012  >  Lecture Notes for Wednesday, February 15, 2012

CS 321 Spring 2012
Lecture Notes for Wednesday, February 15, 2012

Shared-Memory IPC (cont’d)

Problems When Using Mutual Exclusion

The Priority-Inversion Problem happens when we have a high-priority process/thread busy-waiting on a lower-priority process/thread. We need to give time to the lower-priority process so that it can finish and the higher-priority one can do its work. But standard scheduling algorithms will give more time to the higher-priority process. This is another reason to avoid busy waiting.

The Producer-Consumer Problem occurs when data is being transfered from a “producer” process to a “consumer” process. To avoid busy-waiting, we might have the consumer process check if there is data available, and if not, sleep. Now suppose there is an interrupt between a check (which says there is no data) and the sleep. Then the producer can send data, and wake the consumer ... which is already awake and preparing to sleep. So the producer sends data, and the consumer responds by sleeping. This is another situation when atomic operations are needed.

Kernel-Provided Mechanisms for Handling Shared Resources

We discussed semaphores, and in particular binary semaphores, and mutexes. All of these are provided by the kernel, and must perform atomic operations.

We looked at mutexes as implemented in pThreads.

A monitor is mutual exclusion encapsulated. For example, we could write a class whose constructor acquires a lock and whose destructor releases it.

CS 321 Spring 2012: Lecture Notes for Wednesday, February 15, 2012 / Updated: 2 May 2012 / Glenn G. Chappell / ggchappell@alaska.edu