0% found this document useful (0 votes)
65 views7 pages

Unit 3 of OS

Conditional critical regions ensure that only one process can execute a specific region at a time, maintaining mutual exclusion, atomicity, and synchronization. Monitors provide a higher-level synchronization mechanism that encapsulates shared resources and simplifies concurrent programming. Interprocess communication (IPC) methods, including message passing, shared memory, pipes, and signals, facilitate data sharing and coordination between processes.

Uploaded by

jaisingh2744
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views7 pages

Unit 3 of OS

Conditional critical regions ensure that only one process can execute a specific region at a time, maintaining mutual exclusion, atomicity, and synchronization. Monitors provide a higher-level synchronization mechanism that encapsulates shared resources and simplifies concurrent programming. Interprocess communication (IPC) methods, including message passing, shared memory, pipes, and signals, facilitate data sharing and coordination between processes.

Uploaded by

jaisingh2744
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Conditional critical regions

Conditional critical regions are the regions in a program that must be executed
distinctly by one process and no other process can execute that region at the same
time. When we use condition variables for locking purposes then the critical regions
are referred to as conditional critical regions.

Critical Region Characteristics and Requirements


Following are the characteristics and requirements for critical regions in an operating
system.

1. Mutual Exclusion

Only one procedure or thread can access the important region at a time. This ensures
that concurrent entry does not bring about facts corruption or inconsistent states.

2. Atomicity

The execution of code within an essential region is dealt with as an indivisible unit of
execution. This way that after a system or thread enters a vital place, it completes its
execution without interruption.

3. Synchronization

Processes or threads waiting to go into an essential vicinity are synchronized to prevent


simultaneous access. They commonly appoint synchronization primitives, inclusive of
locks or semaphores, to govern access and put in force mutual exclusion.

4. Minimal Time Spent in Critical Regions

It is perfect to reduce the time spent inside crucial regions to reduce the capacity for
contention and improve gadget overall performance. Lengthy execution within essential
regions can increase the waiting time for different strategies or threads.
Monitors in Process Synchronization
Monitors are a higher-level synchronization construct that simplifies process
synchronization by providing a high-level abstraction for data access and
synchronization. Monitors are implemented as programming language constructs,
typically in object-oriented languages, and provide mutual exclusion, condition
variables, and data encapsulation in a single construct.

1.​ A monitor is essentially a module that encapsulates a shared resource and


provides access to that resource through a set of procedures. The
procedures provided by a monitor ensure that only one process can
access the shared resource at any given time, and that processes waiting
for the resource are suspended until it becomes available.
2.​ Monitors are used to simplify the implementation of concurrent programs
by providing a higher-level abstraction that hides the details of
synchronization. Monitors provide a structured way of sharing data and
synchronization information, and eliminate the need for complex
synchronization primitives such as semaphores and locks.
3.​ The key advantage of using monitors for process synchronization is that
they provide a simple, high-level abstraction that can be used to implement
complex concurrent systems. Monitors also ensure that synchronization is
encapsulated within the module, making it easier to reason about the
correctness of the system.

However, monitors have some limitations. For example, they can be less efficient
than lower-level synchronization primitives such as semaphores and locks, as they
may involve additional overhead due to their higher-level abstraction. Additionally,
monitors may not be suitable for all types of synchronization problems, and in
some cases, lower-level primitives may be required for optimal performance.
The monitor is one of the ways to achieve Process synchronization. The monitor is
supported by programming languages to achieve mutual exclusion between
processes. For example Java Synchronized methods. Java provides wait() and
notify() constructs.

1.​ It is the collection of condition variables and procedures combined


together in a special kind of module or a package.
2.​ The processes running outside the monitor can’t access the internal
variable of the monitor but can call procedures of the monitor.
3.​ Only one process at a time can execute code inside monitors.

Syntax: Condition Variables: Two different


operations are performed on the condition variables of the monitor.

Wait.

signal.

let say we have 2 condition variables condition x, y; // Declaring variable Wait


operation x.wait() : Process performing wait operation on any condition variable are
suspended. The suspended processes are placed in block queue of that condition
variable. Note: Each condition variable has its unique block queue. Signal
operation x.signal(): When a process performs signal operation on condition
variable, one of the blocked processes is given chance.
Interprocess Communication in Operating
System
Interprocess communication (IPC) is a process that allows different processes of a computer
system to share information. IPC lets different programs run in parallel, share data, and
communicate with each other. It’s important for two reasons: First, it speeds up the execution
of tasks, and secondly, it ensures that the tasks run correctly and in the order that they were
executed.

Why Interprocess Communication is Necessary

IPC lets different programs run in parallel, share data, and communicate with each other. It’s
important for two reasons:

●​ It speeds up the execution of tasks.


●​ It ensures that the tasks run correctly and in the order that they were executed.
●​ IPC is essential for the efficient operation of an operating system.

How to do Interprocess Communication

1. Message Passing

We will start our discussion of the communication between processes via message

passing. In this method, processes communicate with each other without using any

kind of shared memory. If two processes p1 and p2 want to communicate with each

other, they proceed as follows:


●​ Establish a communication link (if a link already exists, no need to establish it

again.)

●​ Start exchanging messages using basic primitives.​

We need at least two primitives:​

– send (message, destination) or send (message)​

– receive (message, host) or receive (message)

2. Shared memory
Shared memory is a memory shared between all processes by two or more processes
established using shared memory. This type of memory should protect each other by
synchronizing access between all processes. Both processes, like A and B, can set up a
shared memory segment and exchange data through this shared memory area. Shared
memory is important for these reasons-

●​ It is a way of passing data between processes.


●​ Shared memory is much faster and more reliable than these methods.
●​ Shared memory allows two or more processes to share the same copy of the data.

Suppose process A wants to communicate with process B and needs to attach its address
space to this shared memory segment. Process A will write a message to the shared memory,
and Process B will read that message from the shared memory. So, processes are responsible
for ensuring synchronization so that both processes do not write to the same location at the
same time.

Let’s discuss an example of communication between processes using the shared


memory method.

Exp: Producer-Consumer problem

There are two processes: Producer and Consumer . The producer produces some
items and the Consumer consumes that item. The two processes share a common
space or memory location known as a buffer where the item produced by the
Producer is stored and from which the Consumer consumes the item if needed.

There are two versions of this problem: the first one is known as the unbounded
buffer problem in which the Producer can keep on producing items and there is no
limit on the size of the buffer, the second one is known as the bounded buffer
problem in which the Producer can produce up to a certain number of items before it
starts waiting for Consumer to consume it. We will discuss the bounded buffer
problem.
First, the Producer and the Consumer will share some common memory, then the
producer will start producing items. If the total produced item is equal to the size of
the buffer, the producer will wait to get it consumed by the Consumer. Similarly, the
consumer will first check for the availability of the item. If no item is available, the
Consumer will wait for the Producer to produce it. If there are items available,
Consumer will consume them. The pseudo-code to demonstrate is provided below:

3. Pipes
Pipes are a type of data channel commonly used for one-way communication between two
processes. Because this is a half-duplex technique, the primary process communicates with
the secondary process. However, additional lines are required to achieve a full duplex. The
two pipes create a bidirectional data channel between the two processes. But one pipe creates
a unidirectional data channel. Pipes are primarily used on Windows operating systems. Like in
the diagram it is shown that one process will send a message to the pipe. The message will be
retrieved, and another process will write it to the standard output.

4. Signal
The signal is a facility that allows processes to communicate with each other. A signal is a
way of telling a process that it needs to do something. A process can send a signal to another
process. A signal also allows a process to interrupt another process. A signal is a way of
communicating between processes.

You might also like