0% found this document useful (0 votes)
21 views9 pages

Module-3 OS

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

Module-3 OS

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

CSE2008 – Operating Systems

Dr. Venkata Rami Reddy Ch


Sr.Assistant Professor
School of Computer Science & Engineering
VIT-AP University
Module-3: Process Coordination and Deadlock

• Process synchronization, critical-section problem, Peterson's solution,


synchronization hardware, semaphores,classic problems of
synchronization. System model, deadlock characterization, methods for
handling deadlocks, deadlock prevention, deadlock avoidance, deadlock
detection, recovery from deadlock.

Dr. Venkata Rami Reddy Ch , Sr. Assistant Professor, SCOPE


Process synchronization

• Independent Process - The process that does not share any shared variable,
database, files, etc.
• Cooperating Process - The process that share file, variable, database, etc are
the Cooperating Process.
• Concurrent access to shared data may result in data inconsistency,

Dr. Venkata Rami Reddy Ch , Sr. Assistant Professor, SCOPE


Producer process Consumer process

• suppose that the value of the variable counter is currently 5 and that the producer and
consumer processes concurrently execute the statements “counter++” and “counter--”.
• Following the execution of these two statements, the value of the variable counter may be
4, 5, or 6!
• The only correct result, though, is counter == 5, which is generated correctly if the producer
and consumer executed in synchronized manner.
Dr. Venkata Rami Reddy Ch , Sr. Assistant Professor, SCOPE
Process synchronization

• We would arrive at this incorrect state(data inconsistency) because we allowed


both processes to manipulate the variable count concurrently.
• A situation like this, leads to race condition
• Where several processes access and manipulate the same data concurrently and
the outcome of the execution depends on the particular order in which the access
takes place, is called a race condition.
• To guard against the race condition above, we need to ensure that only one
process at a time can be manipulating the variable count.
• To make such a guarantee, we require that the processes be synchronized in some
way.

Dr. Venkata Rami Reddy Ch , Sr. Assistant Professor, SCOPE


Process synchronization

• Process Synchronization, in which we allow only one process to enter and


manipulates the shared data at a time.

Why Do We Need Process Synchronization?


1. To avoid Race Conditions
2. To ensure Data Consistency
• Shared resources (like databases, memory, files) must always stay consistent.
• Synchronization ensures only one process updates a resource at a time.
3. For Coordinated Execution

Dr. Venkata Rami Reddy Ch , Sr. Assistant Professor, SCOPE


Critical-Section Problem
• Consider a system consisting of n processes {P0, P1,..., Pn−1}.
• A Critical Section is a section of code common to cooperating processes, where
the process may be accessing and updating shared data (like variables, files,
databases).
• The Critical Section Problem arises when multiple processes access and update
share resources at the same time.
• The important feature of the system is that, when one process is executing in its
critical section, no other process is allowed to execute in its critical section.
• That is, no two processes are executing in their critical sections at the same time.
• The critical-section problem is to design a protocol that the processes can be
allowed to share data without causing data inconsistencies.

Dr. Venkata Rami Reddy Ch , Sr. Assistant Professor, SCOPE


Critical-Section Problem
Critical Section General structure of process Pi
•The part of a process where shared variables or
resources are accessed/modified.
Entry Section
•The entry section is the part of code where a process
requests permission to enter its critical section
Exit Section
•The exit section is the part of the code where a
process leaves its critical section and signals other
processes that they can enter.
Remainder Section
• The rest of the process outside the critical section,
which does not use shared resources..

Dr. Venkata Rami Reddy Ch , Sr. Assistant Professor, SCOPE


Requirements of a CSP Solution
• Any solution to the Critical-Section Problem must satisfy these three conditions:
Mutual Exclusion
• Only one process at a time can be executing in their critical section.
Progress
• If no process is executing in its critical section and some processes wish
to enter their critical sections, then only those processes that are not
executing in their remainder sections can participate in deciding which
will enter its critical section next, and this selection cannot be postponed
indefinitely
Bounded waiting
• There exists a limit on the number of times that other processes are
allowed to enter their critical sections after a process has made a request to
enter its critical section and before that request is granted.
Dr. Venkata Rami Reddy Ch , Sr. Assistant Professor, SCOPE

You might also like