SlideShare a Scribd company logo
1 of 22
JMHM Jayamaha
SEU/IS/10/PS/104
PS0372
 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;
}
}
 Shared variables
 boolean flag[2];
initially flag [0] = flag [1] = false.
 flag [i] = true  Pi ready to enter its critical section
 Process Pi
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;
public Algorithm_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.
Operating system   critical section
Operating system   critical section

More Related Content

What's hot

Cpu scheduling in operating System.
Cpu scheduling in operating System.Cpu scheduling in operating System.
Cpu scheduling in operating System.Ravi Kumar Patel
 
Peterson Critical Section Problem Solution
Peterson Critical Section Problem SolutionPeterson Critical Section Problem Solution
Peterson Critical Section Problem SolutionBipul Chandra Kar
 
Deadlock detection and recovery by saad symbian
Deadlock detection and recovery by saad symbianDeadlock detection and recovery by saad symbian
Deadlock detection and recovery by saad symbiansaad symbian
 
Multithreading models.ppt
Multithreading models.pptMultithreading models.ppt
Multithreading models.pptLuis Goldster
 
Process scheduling (CPU Scheduling)
Process scheduling (CPU Scheduling)Process scheduling (CPU Scheduling)
Process scheduling (CPU Scheduling)Mukesh Chinta
 
Moore and mealy machine
Moore and mealy machineMoore and mealy machine
Moore and mealy machineMian Munib
 
Compiler Design
Compiler DesignCompiler Design
Compiler DesignMir Majid
 
Methods for handling deadlock
Methods for handling deadlockMethods for handling deadlock
Methods for handling deadlocksangrampatil81
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic NotationsRishabh Soni
 
input/ output in java
input/ output  in javainput/ output  in java
input/ output in javasharma230399
 
Semophores and it's types
Semophores and it's typesSemophores and it's types
Semophores and it's typesNishant Joshi
 
Deadlock Avoidance - OS
Deadlock Avoidance - OSDeadlock Avoidance - OS
Deadlock Avoidance - OSMsAnita2
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OSvampugani
 

What's hot (20)

Cpu scheduling in operating System.
Cpu scheduling in operating System.Cpu scheduling in operating System.
Cpu scheduling in operating System.
 
Peterson Critical Section Problem Solution
Peterson Critical Section Problem SolutionPeterson Critical Section Problem Solution
Peterson Critical Section Problem Solution
 
Process scheduling
Process schedulingProcess scheduling
Process scheduling
 
Deadlock detection and recovery by saad symbian
Deadlock detection and recovery by saad symbianDeadlock detection and recovery by saad symbian
Deadlock detection and recovery by saad symbian
 
Multithreading models.ppt
Multithreading models.pptMultithreading models.ppt
Multithreading models.ppt
 
Process scheduling (CPU Scheduling)
Process scheduling (CPU Scheduling)Process scheduling (CPU Scheduling)
Process scheduling (CPU Scheduling)
 
Moore and mealy machine
Moore and mealy machineMoore and mealy machine
Moore and mealy machine
 
Process scheduling
Process schedulingProcess scheduling
Process scheduling
 
Monitors
MonitorsMonitors
Monitors
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
Critical section operating system
Critical section  operating systemCritical section  operating system
Critical section operating system
 
Methods for handling deadlock
Methods for handling deadlockMethods for handling deadlock
Methods for handling deadlock
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 
Mainframe systems
Mainframe systemsMainframe systems
Mainframe systems
 
input/ output in java
input/ output  in javainput/ output  in java
input/ output in java
 
Process synchronization
Process synchronizationProcess synchronization
Process synchronization
 
Semophores and it's types
Semophores and it's typesSemophores and it's types
Semophores and it's types
 
Deadlock Avoidance - OS
Deadlock Avoidance - OSDeadlock Avoidance - OS
Deadlock Avoidance - OS
 
Process state in OS
Process state in OSProcess state in OS
Process state in OS
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OS
 

Viewers also liked

Operating System Process Synchronization
Operating System Process SynchronizationOperating System Process Synchronization
Operating System Process SynchronizationHaziq Naeem
 
Unit II - 3 - Operating System - Process Synchronization
Unit II - 3 - Operating System - Process SynchronizationUnit II - 3 - Operating System - Process Synchronization
Unit II - 3 - Operating System - Process Synchronizationcscarcas
 
Operating System Deadlock Galvin
Operating System  Deadlock GalvinOperating System  Deadlock Galvin
Operating System Deadlock GalvinSonali Chauhan
 
Operating Systems - Synchronization
Operating Systems - SynchronizationOperating Systems - Synchronization
Operating Systems - SynchronizationEmery Berger
 
Chapter 6 - Process Synchronization
Chapter 6 - Process SynchronizationChapter 6 - Process Synchronization
Chapter 6 - Process SynchronizationWayne Jones Jnr
 
Process synchronization(deepa)
Process synchronization(deepa)Process synchronization(deepa)
Process synchronization(deepa)Nagarajan
 
Web Tech
Web TechWeb Tech
Web TechRupsee
 
OS Process Synchronization, semaphore and Monitors
OS Process Synchronization, semaphore and MonitorsOS Process Synchronization, semaphore and Monitors
OS Process Synchronization, semaphore and Monitorssgpraju
 
Process Synchronization And Deadlocks
Process Synchronization And DeadlocksProcess Synchronization And Deadlocks
Process Synchronization And Deadlockstech2click
 

Viewers also liked (11)

Operating System Process Synchronization
Operating System Process SynchronizationOperating System Process Synchronization
Operating System Process Synchronization
 
Web technology
Web technologyWeb technology
Web technology
 
Unit II - 3 - Operating System - Process Synchronization
Unit II - 3 - Operating System - Process SynchronizationUnit II - 3 - Operating System - Process Synchronization
Unit II - 3 - Operating System - Process Synchronization
 
Operating System Deadlock Galvin
Operating System  Deadlock GalvinOperating System  Deadlock Galvin
Operating System Deadlock Galvin
 
Operating Systems - Synchronization
Operating Systems - SynchronizationOperating Systems - Synchronization
Operating Systems - Synchronization
 
Chapter 6 - Process Synchronization
Chapter 6 - Process SynchronizationChapter 6 - Process Synchronization
Chapter 6 - Process Synchronization
 
Process synchronization(deepa)
Process synchronization(deepa)Process synchronization(deepa)
Process synchronization(deepa)
 
Web Tech
Web TechWeb Tech
Web Tech
 
OS Process Synchronization, semaphore and Monitors
OS Process Synchronization, semaphore and MonitorsOS Process Synchronization, semaphore and Monitors
OS Process Synchronization, semaphore and Monitors
 
Process synchronization in operating system
Process synchronization in operating systemProcess synchronization in operating system
Process synchronization in operating system
 
Process Synchronization And Deadlocks
Process Synchronization And DeadlocksProcess Synchronization And Deadlocks
Process Synchronization And Deadlocks
 

Similar to Operating system critical section

Critical Section Problem - Ramakrishna Reddy Bijjam
Critical Section Problem - Ramakrishna Reddy BijjamCritical Section Problem - Ramakrishna Reddy Bijjam
Critical Section Problem - Ramakrishna Reddy BijjamRamakrishna Reddy Bijjam
 
14- Process Synchronization.pptx
14- Process Synchronization.pptx14- Process Synchronization.pptx
14- Process Synchronization.pptxmobeenahmed49
 
Process synchronization
Process synchronizationProcess synchronization
Process synchronizationAbeera Naeem
 
Ch7 OS
Ch7 OSCh7 OS
Ch7 OSC.U
 
criticalsectionproblem-160905215747.pdf
criticalsectionproblem-160905215747.pdfcriticalsectionproblem-160905215747.pdf
criticalsectionproblem-160905215747.pdfBhanuCharan9
 
Operating system 23 process synchronization
Operating system 23 process synchronizationOperating system 23 process synchronization
Operating system 23 process synchronizationVaibhav Khanna
 
Mutual Exclusion using Peterson's Algorithm
Mutual Exclusion using Peterson's AlgorithmMutual Exclusion using Peterson's Algorithm
Mutual Exclusion using Peterson's AlgorithmSouvik Roy
 
Synchronization in os.pptx
Synchronization in os.pptxSynchronization in os.pptx
Synchronization in os.pptxAbdullahBhatti53
 
Process Synchronization
Process SynchronizationProcess Synchronization
Process SynchronizationSonali Chauhan
 
Process Synchronization -1.ppt
Process Synchronization -1.pptProcess Synchronization -1.ppt
Process Synchronization -1.pptjayverma27
 
computer programming and utilization
computer programming and utilizationcomputer programming and utilization
computer programming and utilizationJAYDEV PATEL
 
Lecture 5- Process Synchronization (1).pptx
Lecture 5- Process Synchronization (1).pptxLecture 5- Process Synchronization (1).pptx
Lecture 5- Process Synchronization (1).pptxAmanuelmergia
 

Similar to Operating system critical section (20)

Critical Section Problem - Ramakrishna Reddy Bijjam
Critical Section Problem - Ramakrishna Reddy BijjamCritical Section Problem - Ramakrishna Reddy Bijjam
Critical Section Problem - Ramakrishna Reddy Bijjam
 
14- Process Synchronization.pptx
14- Process Synchronization.pptx14- Process Synchronization.pptx
14- Process Synchronization.pptx
 
CH05.pdf
CH05.pdfCH05.pdf
CH05.pdf
 
Process synchronization
Process synchronizationProcess synchronization
Process synchronization
 
Operating System
Operating SystemOperating System
Operating System
 
Ch7 OS
Ch7 OSCh7 OS
Ch7 OS
 
criticalsectionproblem-160905215747.pdf
criticalsectionproblem-160905215747.pdfcriticalsectionproblem-160905215747.pdf
criticalsectionproblem-160905215747.pdf
 
OSCh7
OSCh7OSCh7
OSCh7
 
OS_Ch7
OS_Ch7OS_Ch7
OS_Ch7
 
Operating system 23 process synchronization
Operating system 23 process synchronizationOperating system 23 process synchronization
Operating system 23 process synchronization
 
6 Synchronisation
6 Synchronisation6 Synchronisation
6 Synchronisation
 
Mutual Exclusion using Peterson's Algorithm
Mutual Exclusion using Peterson's AlgorithmMutual Exclusion using Peterson's Algorithm
Mutual Exclusion using Peterson's Algorithm
 
Synchronization in os.pptx
Synchronization in os.pptxSynchronization in os.pptx
Synchronization in os.pptx
 
Ch7
Ch7Ch7
Ch7
 
Process Synchronization
Process SynchronizationProcess Synchronization
Process Synchronization
 
Lecture16-17.ppt
Lecture16-17.pptLecture16-17.ppt
Lecture16-17.ppt
 
Mutual exclusion and sync
Mutual exclusion and syncMutual exclusion and sync
Mutual exclusion and sync
 
Process Synchronization -1.ppt
Process Synchronization -1.pptProcess Synchronization -1.ppt
Process Synchronization -1.ppt
 
computer programming and utilization
computer programming and utilizationcomputer programming and utilization
computer programming and utilization
 
Lecture 5- Process Synchronization (1).pptx
Lecture 5- Process Synchronization (1).pptxLecture 5- Process Synchronization (1).pptx
Lecture 5- Process Synchronization (1).pptx
 

More from Harshana Madusanka Jayamaha

More from Harshana Madusanka Jayamaha (8)

Handwritten character recognition using artificial neural network
Handwritten character recognition using artificial neural networkHandwritten character recognition using artificial neural network
Handwritten character recognition using artificial neural network
 
Linear and non linear equation
Linear and non linear equationLinear and non linear equation
Linear and non linear equation
 
Clipping ( Cohen-Sutherland Algorithm )
Clipping ( Cohen-Sutherland Algorithm )Clipping ( Cohen-Sutherland Algorithm )
Clipping ( Cohen-Sutherland Algorithm )
 
Advance operator and technique in genetic algorithm
Advance operator and technique in genetic algorithmAdvance operator and technique in genetic algorithm
Advance operator and technique in genetic algorithm
 
Artificial Neural Network Topology
Artificial Neural Network TopologyArtificial Neural Network Topology
Artificial Neural Network Topology
 
Parallel algorithm in linear algebra
Parallel algorithm in linear algebraParallel algorithm in linear algebra
Parallel algorithm in linear algebra
 
Organizational structure
Organizational structureOrganizational structure
Organizational structure
 
Distributed System - Security
Distributed System - SecurityDistributed System - Security
Distributed System - Security
 

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 

Recently uploaded (20)

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

Operating system critical section

  • 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.  Shared variables  boolean flag[2]; initially flag [0] = flag [1] = false.  flag [i] = true  Pi ready to enter its critical section  Process Pi 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; public Algorithm_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.