Lec 14 Reader Writer Problem and Monitor
Lec 14 Reader Writer Problem and Monitor
SYSTEM:
ACSE0403A
OUTLINE
Let's understand with an example - If two or more than two readers want to access the file at the
same point in time there will be no problem. However, in other situations like when two writers or
one reader and one writer wants to access the file at the same point of time, there may occur some
problems, hence the task is to design the code in such a manner that if one reader is reading then
no writer is allowed to update at the same point of time, similarly, if one writer is writing no reader
is allowed to read the file at that point of time and if one writer is updating a file other writers
should not be allowed to update the file at the same point of time. However, multiple readers can
access the object at the same time.
SOLUTION FOR READER WRITER PROBLEM?
The solution of readers and writers can
be implemented using binary
semaphores.
In the above code of
reader, mutex and write are semaph
ores that have an initial value of 1,
whereas the readcount variable has
an initial value as 0.
Both mutex and write are common in
reader and writer process code,
semaphore mutex ensures mutual
exclusion and semaphore write
handles the writing mechanism.
MONITOR
Advantages
1. Mutual exclusion is automatic in monitors.
2. Monitors are less difficult to implement than semaphores.
3. Monitors may overcome the timing errors that occur when semaphores are used.
4. Monitors are a collection of procedures and condition variables that are combined in a
special type of module.
Limitations:
5. Monitors must be implemented into the programming language.
6. The compiler should generate code for them.
7. It gives the compiler the additional burden of knowing what operating system features
is available for controlling access to crucial sections in concurrent processes.
SEMAPHORE VS MONITOR
Thank
You