8
Most read
19
Most read
20
Most read
RAMAKRISHNA REDDY BIJJAM
Assistant Professor
AVANTHI PG COLLEGE
Hyderabad
9966484777
Definition
Example of Critical section problem
Solution to critical section problem
Software solution
 Algorithm 1
 Algorithm 2
 Algorithm 3
Critical Region
When a process is accessing shared
modifiable data or a resource that can only
operate on behalf of one process at a time ,
the process is said to be in a critical section.
When one process is in a critical section , all
other processes (at least those that access
the shared modifiable data and/or resource)
are excluded from their critical section.
 n processes all competing to use some shared data
 Each process has a code segment, called critical section, in which
the shared data is accessed.
 Problem – ensure that when one process is executing in its critical
section, no other process is allowed to execute in its critical section.
 Transfer Rs. 100 from saving account to checking account
P1 P2
Saving = saving – 100 saving = saving * 1.01
Checking = checking +100 checking = checking * 101
Initially : saving = 100
checking = 0
P1 ran first & P2 ran first & P1’s first line then P2
P2 ran second p1 ran second & P1’s second line
Saving = 0 saving = 1 saving = 0
Checking = 101 checking = 100 checking = 100
1. Mutual Exclusion. If process Pi is executing in its critical section,
then no other processes can be executing in their critical sections.
2. Progress. If no process is executing in its critical section and
there exist some processes that wish to enter their critical
section, then the selection of the processes that will enter the
critical section next cannot be postponed indefinitely.
3. Bounded Waiting. A bound must exist 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.
 Assume that each process executes at a nonzero speed
 No assumption concerning relative speed of the n processes.
 Only 2 processes, P0 and P1
 General structure of process Pi (other process Pj)
do {
entry section
critical section
exit section
reminder section
} while (1);
 Processes may share some common variables to synchronize their
actions.
 Shared variables:
 int turn;
initially turn = 0
 turn = i Pi can enter its critical section
 Process Pi
do {
while (turn != i) ;
critical section
turn = j;
reminder section
} while (1);
 Satisfies mutual exclusion, but not progress
 Does this algorithm satisfy the 3 criteria mentioned.
◦ Mutual Exclusion
◦ Progress
◦ Bounded wait
public class Algorithm_1 implements MutualExclusion {
private volatile int turn;
public Algorithm_1() {
turn = TURN_0;
}
public void enteringCriticalSection(int t) {
while(turn != t)
Thread.yield();
}
public void leavingCriticalSection(int t){
turn = 1 - t;
}
}
 Sharedvariables
 boolean flag[2];
initially flag [0] = flag [1] = false.
 flag [i] = true  Pi ready to enter its critical section
 ProcessPi
do {
flag[i] := true;
while (flag[j]) ;
critical section
flag [i] = false;
remainder section
} while (1);
 Satisfies mutual exclusion, but not progress requirement.
 Does this algorithm satisfy the 3 criteria mentioned.
◦ Mutual Exclusion
◦ Progress
◦ Bounded wait
public class Algorithm_2 implements MutualExclusion {
private volatile boolean flag0;
private volatile boolean flag1;
public Algorithm_2() {
flag0 = false;
flag1 = false;
}
public void enteringCriticalSection(int t) {
if(t == 0){
flag0 = true;
while(flag1 == true)
Thread.yield();
} else {
flag1 = false;
while(flag0 == true)
Thread.yield();
}
}
public void leavingCriticalSection(int t) {
if(t == 0)
flag0 = false;
else
flag1 = false;
}
}
 Combined shared variables of algorithms 1 and 2.
 Process Pi
do {
flag [i]:= true;
turn = j;
while (flag [j] and turn = j) ;
critical section
flag [i] = false;
remainder section
} while (1);
 Meets all three requirements; solves the critical-
section problem for two processes.
 Does this algorithm satisfy the 3 criteria mentioned.
◦ Mutual Exclusion
◦ Progress
◦ Bounded wait
public class Algorithm_3 implements MutualExclusion {
private volatile int turn;
private volatile boolean flag0;
private volatile boolean flag1;
publicAlgorithm_3() {
flag0 = false;
flag1 = false;
turn = TURN_0;
}
public void enteringCriticalSection( int t) {
int other = 1 - t;
turn = other;
if(t == 0) {
flag0 = true;
while((flag0 == true) && (turn == other))
Thread.yield();
} else {
flag1 = true;
while((flag0 == true) && (turn == other))
Thread.yield();
}
}
public void leavingCriticalSection( int t) {
if(t == 0)
flag0 = false;
else
flag1 = false;
}
}
 High-level synchronization construct
 A shared variable v of type T, is declared as:
v: shared T
 Variable v accessed only inside statement
region v when B do S
where B is a boolean expression.
 While statement S is being executed, no other
process can access variable v.
 Regions referring to the same shared variable
exclude each other in time.
 When a process tries to execute the region
statement, the Boolean expression B is
evaluated. If B is true, statement S is
executed. If it is false, the process is delayed
until B becomes true and no other process is
in the region associated with v.
Critical Section Problem - Ramakrishna Reddy Bijjam
Critical Section Problem - Ramakrishna Reddy Bijjam

More Related Content

PPT
Indexing Data Structure
PPTX
Structure of the page table
PDF
Software Process Models
PPT
Peterson Critical Section Problem Solution
PPTX
Type checking compiler construction Chapter #6
PPTX
Walkthrough and inspection (Walkthrough)
PPTX
Real Time OS For Embedded Systems
PPT
Real-Time Operating Systems
Indexing Data Structure
Structure of the page table
Software Process Models
Peterson Critical Section Problem Solution
Type checking compiler construction Chapter #6
Walkthrough and inspection (Walkthrough)
Real Time OS For Embedded Systems
Real-Time Operating Systems

What's hot (20)

PPT
PPT
Unit 5 usability and satisfaction test
PPTX
Disk Scheduling Algorithm in Operating System
PPTX
PPT
Instruction Set Architecture
PPTX
PPT
deadlock avoidance
PPTX
Component based software engineering
DOCX
Best,worst,average case .17581556 045
PPT
Software Engineering (Software Process: A Generic View)
PPTX
Context switching
PPTX
Estimating Software Maintenance Costs
PPT
Spiral model presentation
PPTX
INTER PROCESS COMMUNICATION (IPC).pptx
PPTX
Operating system 25 classical problems of synchronization
PPTX
BINARY SEARCH TREE
PPTX
Software Engineering
PPTX
V model presentation
PDF
Domain Modeling
PPTX
6-Role of Parser, Construction of Parse Tree and Elimination of Ambiguity-06-...
Unit 5 usability and satisfaction test
Disk Scheduling Algorithm in Operating System
Instruction Set Architecture
deadlock avoidance
Component based software engineering
Best,worst,average case .17581556 045
Software Engineering (Software Process: A Generic View)
Context switching
Estimating Software Maintenance Costs
Spiral model presentation
INTER PROCESS COMMUNICATION (IPC).pptx
Operating system 25 classical problems of synchronization
BINARY SEARCH TREE
Software Engineering
V model presentation
Domain Modeling
6-Role of Parser, Construction of Parse Tree and Elimination of Ambiguity-06-...
Ad

Similar to Critical Section Problem - Ramakrishna Reddy Bijjam (20)

PPTX
Operating system critical section
PDF
OperatingSystem-Unit2_Process Management
PPTX
14- Process Synchronization.pptx
PPTX
Chapter6 Synchronization in Operating systems.pptx
PPT
Process synchronization(deepa)
PPTX
Process synchronization
PDF
OS Process synchronization Unit3 synchronization
PPT
Operating System
PPTX
Critical section problem in operating system.
PDF
criticalsectionproblem-160905215747.pdf
PDF
CH05.pdf
PPTX
process synchronization topic of operating system
PPTX
Operating system 23 process synchronization
PPTX
Describing the Peterson solution sw.pptx
PPTX
Mutual Exclusion using Peterson's Algorithm
PPT
Ch7 OS
 
PPT
PPT
PDF
6 Synchronisation
Operating system critical section
OperatingSystem-Unit2_Process Management
14- Process Synchronization.pptx
Chapter6 Synchronization in Operating systems.pptx
Process synchronization(deepa)
Process synchronization
OS Process synchronization Unit3 synchronization
Operating System
Critical section problem in operating system.
criticalsectionproblem-160905215747.pdf
CH05.pdf
process synchronization topic of operating system
Operating system 23 process synchronization
Describing the Peterson solution sw.pptx
Mutual Exclusion using Peterson's Algorithm
Ch7 OS
 
6 Synchronisation
Ad

More from Ramakrishna Reddy Bijjam (20)

PPTX
Probability Distribution Reviewing Probability Distributions.pptx
PPTX
Combining data and Customizing the Header NamesSorting.pptx
PPTX
python plotting's and its types with examples.pptx
PPTX
Statistics and its measures with Python.pptx
PPTX
DataStructures in Pyhton Pandas and numpy.pptx
PPTX
Pyhton with Mysql to perform CRUD operations.pptx
PPTX
Regular expressions,function and glob module.pptx
PPTX
Natural Language processing using nltk.pptx
PPTX
Parsing HTML read and write operations and OS Module.pptx
PPTX
JSON, XML and Data Science introduction.pptx
PPTX
What is FIle and explanation of text files.pptx
PPTX
BINARY files CSV files JSON files with example.pptx
DOCX
VBS control structures for if do whilw.docx
DOCX
Builtinfunctions in vbscript and its types.docx
DOCX
VBScript Functions procedures and arrays.docx
DOCX
VBScript datatypes and control structures.docx
PPTX
Numbers and global functions conversions .pptx
DOCX
Structured Graphics in dhtml and active controls.docx
DOCX
Filters and its types as wave shadow.docx
PPTX
JavaScript Arrays and its types .pptx
Probability Distribution Reviewing Probability Distributions.pptx
Combining data and Customizing the Header NamesSorting.pptx
python plotting's and its types with examples.pptx
Statistics and its measures with Python.pptx
DataStructures in Pyhton Pandas and numpy.pptx
Pyhton with Mysql to perform CRUD operations.pptx
Regular expressions,function and glob module.pptx
Natural Language processing using nltk.pptx
Parsing HTML read and write operations and OS Module.pptx
JSON, XML and Data Science introduction.pptx
What is FIle and explanation of text files.pptx
BINARY files CSV files JSON files with example.pptx
VBS control structures for if do whilw.docx
Builtinfunctions in vbscript and its types.docx
VBScript Functions procedures and arrays.docx
VBScript datatypes and control structures.docx
Numbers and global functions conversions .pptx
Structured Graphics in dhtml and active controls.docx
Filters and its types as wave shadow.docx
JavaScript Arrays and its types .pptx

Recently uploaded (20)

PDF
CRP102_SAGALASSOS_Final_Projects_2025.pdf
PDF
Race Reva University – Shaping Future Leaders in Artificial Intelligence
PPTX
B.Sc. DS Unit 2 Software Engineering.pptx
PDF
Complications of Minimal Access-Surgery.pdf
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
PDF
semiconductor packaging in vlsi design fab
PDF
BP 505 T. PHARMACEUTICAL JURISPRUDENCE (UNIT 2).pdf
PPTX
Unit 4 Computer Architecture Multicore Processor.pptx
PPTX
Share_Module_2_Power_conflict_and_negotiation.pptx
PPTX
Module on health assessment of CHN. pptx
PDF
Empowerment Technology for Senior High School Guide
PDF
LIFE & LIVING TRILOGY- PART (1) WHO ARE WE.pdf
PDF
My India Quiz Book_20210205121199924.pdf
PDF
LEARNERS WITH ADDITIONAL NEEDS ProfEd Topic
PPTX
Introduction to pro and eukaryotes and differences.pptx
PDF
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
PDF
Literature_Review_methods_ BRACU_MKT426 course material
PDF
LIFE & LIVING TRILOGY - PART - (2) THE PURPOSE OF LIFE.pdf
PDF
Journal of Dental Science - UDMY (2022).pdf
PPTX
Core Concepts of Personalized Learning and Virtual Learning Environments
CRP102_SAGALASSOS_Final_Projects_2025.pdf
Race Reva University – Shaping Future Leaders in Artificial Intelligence
B.Sc. DS Unit 2 Software Engineering.pptx
Complications of Minimal Access-Surgery.pdf
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
semiconductor packaging in vlsi design fab
BP 505 T. PHARMACEUTICAL JURISPRUDENCE (UNIT 2).pdf
Unit 4 Computer Architecture Multicore Processor.pptx
Share_Module_2_Power_conflict_and_negotiation.pptx
Module on health assessment of CHN. pptx
Empowerment Technology for Senior High School Guide
LIFE & LIVING TRILOGY- PART (1) WHO ARE WE.pdf
My India Quiz Book_20210205121199924.pdf
LEARNERS WITH ADDITIONAL NEEDS ProfEd Topic
Introduction to pro and eukaryotes and differences.pptx
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
Literature_Review_methods_ BRACU_MKT426 course material
LIFE & LIVING TRILOGY - PART - (2) THE PURPOSE OF LIFE.pdf
Journal of Dental Science - UDMY (2022).pdf
Core Concepts of Personalized Learning and Virtual Learning Environments

Critical Section Problem - Ramakrishna Reddy Bijjam

  • 1. RAMAKRISHNA REDDY BIJJAM Assistant Professor AVANTHI PG COLLEGE Hyderabad 9966484777
  • 2. Definition Example of Critical section problem Solution to critical section problem Software solution  Algorithm 1  Algorithm 2  Algorithm 3 Critical Region
  • 3. When a process is accessing shared modifiable data or a resource that can only operate on behalf of one process at a time , the process is said to be in a critical section. When one process is in a critical section , all other processes (at least those that access the shared modifiable data and/or resource) are excluded from their critical section.
  • 4.  n processes all competing to use some shared data  Each process has a code segment, called critical section, in which the shared data is accessed.  Problem – ensure that when one process is executing in its critical section, no other process is allowed to execute in its critical section.
  • 5.  Transfer Rs. 100 from saving account to checking account P1 P2 Saving = saving – 100 saving = saving * 1.01 Checking = checking +100 checking = checking * 101 Initially : saving = 100 checking = 0 P1 ran first & P2 ran first & P1’s first line then P2 P2 ran second p1 ran second & P1’s second line Saving = 0 saving = 1 saving = 0 Checking = 101 checking = 100 checking = 100
  • 6. 1. Mutual Exclusion. If process Pi is executing in its critical section, then no other processes can be executing in their critical sections. 2. Progress. If no process is executing in its critical section and there exist some processes that wish to enter their critical section, then the selection of the processes that will enter the critical section next cannot be postponed indefinitely. 3. Bounded Waiting. A bound must exist 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.  Assume that each process executes at a nonzero speed  No assumption concerning relative speed of the n processes.
  • 7.  Only 2 processes, P0 and P1  General structure of process Pi (other process Pj) do { entry section critical section exit section reminder section } while (1);  Processes may share some common variables to synchronize their actions.
  • 8.  Shared variables:  int turn; initially turn = 0  turn = i Pi can enter its critical section  Process Pi do { while (turn != i) ; critical section turn = j; reminder section } while (1);  Satisfies mutual exclusion, but not progress
  • 9.  Does this algorithm satisfy the 3 criteria mentioned. ◦ Mutual Exclusion ◦ Progress ◦ Bounded wait
  • 10. public class Algorithm_1 implements MutualExclusion { private volatile int turn; public Algorithm_1() { turn = TURN_0; } public void enteringCriticalSection(int t) { while(turn != t) Thread.yield(); } public void leavingCriticalSection(int t){ turn = 1 - t; } }
  • 11.  Sharedvariables  boolean flag[2]; initially flag [0] = flag [1] = false.  flag [i] = true  Pi ready to enter its critical section  ProcessPi do { flag[i] := true; while (flag[j]) ; critical section flag [i] = false; remainder section } while (1);  Satisfies mutual exclusion, but not progress requirement.
  • 12.  Does this algorithm satisfy the 3 criteria mentioned. ◦ Mutual Exclusion ◦ Progress ◦ Bounded wait
  • 13. public class Algorithm_2 implements MutualExclusion { private volatile boolean flag0; private volatile boolean flag1; public Algorithm_2() { flag0 = false; flag1 = false; } public void enteringCriticalSection(int t) { if(t == 0){ flag0 = true; while(flag1 == true) Thread.yield(); } else { flag1 = false; while(flag0 == true) Thread.yield(); } }
  • 14. public void leavingCriticalSection(int t) { if(t == 0) flag0 = false; else flag1 = false; } }
  • 15.  Combined shared variables of algorithms 1 and 2.  Process Pi do { flag [i]:= true; turn = j; while (flag [j] and turn = j) ; critical section flag [i] = false; remainder section } while (1);  Meets all three requirements; solves the critical- section problem for two processes.
  • 16.  Does this algorithm satisfy the 3 criteria mentioned. ◦ Mutual Exclusion ◦ Progress ◦ Bounded wait
  • 17. public class Algorithm_3 implements MutualExclusion { private volatile int turn; private volatile boolean flag0; private volatile boolean flag1; publicAlgorithm_3() { flag0 = false; flag1 = false; turn = TURN_0; } public void enteringCriticalSection( int t) { int other = 1 - t; turn = other; if(t == 0) { flag0 = true; while((flag0 == true) && (turn == other)) Thread.yield(); } else { flag1 = true; while((flag0 == true) && (turn == other)) Thread.yield(); } }
  • 18. public void leavingCriticalSection( int t) { if(t == 0) flag0 = false; else flag1 = false; } }
  • 19.  High-level synchronization construct  A shared variable v of type T, is declared as: v: shared T  Variable v accessed only inside statement region v when B do S where B is a boolean expression.  While statement S is being executed, no other process can access variable v.
  • 20.  Regions referring to the same shared variable exclude each other in time.  When a process tries to execute the region statement, the Boolean expression B is evaluated. If B is true, statement S is executed. If it is false, the process is delayed until B becomes true and no other process is in the region associated with v.