You are on page 1of 2

READERS WRITERS PROBLEM IN OPERATING SYSTEM

The reader-writer problem is a classic synchronization problem in operating


systems where multiple processes require access to a shared resource.
The readers-writers problem relates to an object such as a file that is shared
between multiple processes. Some of these processes are readers i.e. they
only want to read the data from the object and some of the processes are
writers i.e. they want to write into the object.
The readers-writers problem is used to manage synchronization so that
there are no problems with the object data. For example - If two readers
access the object at the same time there is no problem. However if two
writers or a reader and writer access the object at the same time, there may
be problems.
To solve this situation, a writer should get exclusive access to an object i.e.
when a writer is accessing the object, no reader or writer may access it.
However, multiple readers can access the object at the same time.
This can be implemented using semaphores.
Problem parameters:

 One set of data is shared among a number of processes


 Once a writer is ready, it performs its write. Only one writer may
write at a time
 If a process is writing, no other process can read it
 If at least one reader is reading, no other process can write
 Readers may not write and only read

 There are four Types of cases could happen here.

Process
Case 1 Process 2 Allowed/Not Allowed

Case 1 Writing Writing Not Allowed

Case 2 Writing Reading Not Allowed

Case 3 Reading Writing Not Allowed

Case 4 Reading Reading Allowed


MONITORS: Monitor in an operating system is one method for achieving
process synchronization. Programming languages help the monitor to
accomplish mutual exclusion between different activities in a system. wait()
and notify() constructs are synchronization functions that are available in
the Java programming language. Monitors are a programming language
component that aids in the regulation of shared data access. The Monitor is a
package that contains shared data structures, operations, and synchronization
between concurrent procedure calls. Monitors provide a way to ensure that only one
thread or process can access a shared resource at a time, preventing data races and ensuring
proper synchronization. The concept of monitors was introduced by C.A.R. Hoare in 1974.

Advantages of Monitor: Monitors have the advantage of making parallel


programming easier and less error prone than using techniques such as semaphore.
Disadvantages of Monitor: Monitors have to be implemented as part of the
programming language. The compiler must generate code for them. This gives the
compiler the additional burden of having to know what operating system facilities
are available to control access to critical sections in concurrent processes.
Characteristics of Monitors in OS
A monitor in os has the following characteristics:
 We can only run one program at a time inside the monitor.
 Monitors in an operating system are defined as a group of methods
and fields that are combined with a special type of package in the os.
 A program cannot access the monitor's internal variable if it is
running outside the monitor. Although, a program can call the
monitor's functions.
 Monitors were created to make synchronization problems less
complicated.
 Monitors provide a high level of synchronization between processes.

You might also like