Textbook Material
Read the following materials:
Programming Material
The Mutual Exclusion Locks and
Semaphores
sections of the
ThreadMentor notes:
Do the following problems
From our text
Food for Thought 2
Semaphore: Block = 1,
ReadMutex = 1,
ReadCountMutex = 1,
WriteMutex = 1,
WriteCountMutex = 1,
A reader process has the following form:
while {
Wait(Block);
Wait(ReadMutex);
Wait(ReadCountMutex);
ReadCount++;
if (ReadCount == 1)
Wait(WriteMutex);
Signal(ReadCountMutex);
Signal(ReadMutex);
Signal(Block);
..... read the database .....
Wait(ReadCountMutex);
ReadCount--;
if (ReadCount == 0)
Signal(WriteMutex);
Signal(ReadCountMutex);
}
A writer process has the following form:
while {
Wait(WriteCountMutex);
WriteCount++;
if (WriteCount == 1)
Wait(ReadMutex);
Signal(WriteCountMutex);
Wait(WriteMutex);
..... write the database .....
Signal(WriteMutex);
Wait(WriteCountMutex);
WriteCount--;
if (WriteCount == 0)
Signal(ReadMutex);
Signal(WriteCountMutex);
}
The initial values of ReadCount and
WriteCount are both 0. Please study this
solution and answer the following questions:
while {
Wait(Block);
Wait(ReadMutex);
Wait(ReadCountMutex);
ReadCount++;
if (ReadCount == 1)
Wait(WriteMutex);
Signal(ReadCountMutex);
Signal(ReadMutex);
Signal(Block);
...............
}
to the following?
while {
Wait(ReadMutex);
Wait(ReadCountMutex);
ReadCount++;
if (ReadCount == 1)
Wait(WriteMutex);
Signal(ReadCountMutex);
Signal(ReadMutex);
..... read the database .....
Wait(ReadCountMutex);
ReadCount--;
if (ReadCount == 0)
Signal(WriteMutex);
Signal(ReadCountMutex);
}
Removing Block is the most natural
suggestion, since it is used in the reader
process and is used exactly once. Explain
why you cannot do this. If Block is
removed, what will happen to the solution.
| You do not have to turn in your paper. What I really expect you to do is using these problems to gauge your understanding of the subject. So, do the problems after finish reading the above sections. |