SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

Dead Lock in operating system
Dead Lock in operating systemDead Lock in operating system
Dead Lock in operating systemAli Haider
 
Code optimization in compiler design
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler designKuppusamy P
 
Operating system services 9
Operating system services 9Operating system services 9
Operating system services 9myrajendra
 
cpu scheduling
cpu schedulingcpu scheduling
cpu schedulinghashim102
 
DeadLock in Operating-Systems
DeadLock in Operating-SystemsDeadLock in Operating-Systems
DeadLock in Operating-SystemsVenkata Sreeram
 
Threads (operating System)
Threads (operating System)Threads (operating System)
Threads (operating System)Prakhar Maurya
 
Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]Ravindra Raju Kolahalam
 
Page replacement algorithms
Page replacement algorithmsPage replacement algorithms
Page replacement algorithmsPiyush Rochwani
 
Process management os concept
Process management os conceptProcess management os concept
Process management os conceptpriyadeosarkar91
 
Applet life cycle
Applet life cycleApplet life cycle
Applet life cyclemyrajendra
 
Semophores and it's types
Semophores and it's typesSemophores and it's types
Semophores and it's typesNishant Joshi
 
Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handlingNahian Ahmed
 
Inter Process Communication
Inter Process CommunicationInter Process Communication
Inter Process CommunicationAdeel Rasheed
 

Was ist angesagt? (20)

Dead Lock in operating system
Dead Lock in operating systemDead Lock in operating system
Dead Lock in operating system
 
Code optimization in compiler design
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler design
 
Operating system services 9
Operating system services 9Operating system services 9
Operating system services 9
 
cpu scheduling
cpu schedulingcpu scheduling
cpu scheduling
 
DeadLock in Operating-Systems
DeadLock in Operating-SystemsDeadLock in Operating-Systems
DeadLock in Operating-Systems
 
Deadlock dbms
Deadlock dbmsDeadlock dbms
Deadlock dbms
 
CPU Scheduling Algorithms
CPU Scheduling AlgorithmsCPU Scheduling Algorithms
CPU Scheduling Algorithms
 
Context free grammar
Context free grammar Context free grammar
Context free grammar
 
Threads (operating System)
Threads (operating System)Threads (operating System)
Threads (operating System)
 
Operating System: Deadlock
Operating System: DeadlockOperating System: Deadlock
Operating System: Deadlock
 
Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]
 
Page replacement algorithms
Page replacement algorithmsPage replacement algorithms
Page replacement algorithms
 
Process management os concept
Process management os conceptProcess management os concept
Process management os concept
 
Applet life cycle
Applet life cycleApplet life cycle
Applet life cycle
 
Semophores and it's types
Semophores and it's typesSemophores and it's types
Semophores and it's types
 
Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handling
 
serializability in dbms
serializability in dbmsserializability in dbms
serializability in dbms
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
 
Deadlock Prevention
Deadlock PreventionDeadlock Prevention
Deadlock Prevention
 
Inter Process Communication
Inter Process CommunicationInter Process Communication
Inter Process Communication
 

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie 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
 
OS Process synchronization Unit3 synchronization
OS Process synchronization Unit3  synchronizationOS Process synchronization Unit3  synchronization
OS Process synchronization Unit3 synchronizationsubhamchy2005
 
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
 

Ähnlich wie 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
 
OS Process synchronization Unit3 synchronization
OS Process synchronization Unit3  synchronizationOS Process synchronization Unit3  synchronization
OS Process synchronization Unit3 synchronization
 
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
 
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
 

Mehr von Harshana Madusanka Jayamaha

Mehr von 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
 

Kürzlich hochgeladen

Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
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
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 

Kürzlich hochgeladen (20)

Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
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
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 

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.