SlideShare a Scribd company logo
1 of 10
THE CRITICAL-SECTION PROBLEMTHE CRITICAL-SECTION PROBLEM
Video Lecture and E-Content Created byVideo Lecture and E-Content Created by
R.D.SIVAKUMAR,M.Sc.,M.Phil.,M.Tech.,R.D.SIVAKUMAR,M.Sc.,M.Phil.,M.Tech.,
Assistant Professor of Computer Science &Assistant Professor of Computer Science &
Assistant Professor and Head, Department of M.Com.(CA),Assistant Professor and Head, Department of M.Com.(CA),
Ayya Nadar Janaki Ammal College,Ayya Nadar Janaki Ammal College,
Sivakasi – 626 124.Sivakasi – 626 124.
Mobile: 099440-42243Mobile: 099440-42243
e-mail :e-mail : sivamsccsit@gmail.comsivamsccsit@gmail.com website:website: www.rdsivakumar.blogspot.inwww.rdsivakumar.blogspot.in
CRITICAL-SECTIONCRITICAL-SECTION
• A section of code (changing commonA section of code (changing common
variables, updating a table) is shared withvariables, updating a table) is shared with
more than one processes is called criticalmore than one processes is called critical
section.section.
• All the processes wants to access the sameAll the processes wants to access the same
code. But only one process is desired to be incode. But only one process is desired to be in
its critical section.its critical section.
• A critical section that operates on code.A critical section that operates on code.
Example : Railway Reservation SystemExample : Railway Reservation System
• A solution to the critical section problem mustA solution to the critical section problem must
satisfy the following three requirementssatisfy the following three requirements
CRITICAL-SECTION THREE REQUIREMENTSCRITICAL-SECTION THREE REQUIREMENTS
• Mutual Exclusion – At a time, only oneMutual Exclusion – At a time, only one
process should allow to execute in a criticalprocess should allow to execute in a critical
section.section.
• Progress – If no process is in critical sectionProgress – If no process is in critical section
them quickly decide which one process entersthem quickly decide which one process enters
the critical section next.the critical section next.
• Bounded Waiting – It is otherwise called asBounded Waiting – It is otherwise called as
limit waiting. Once a process enters itslimit waiting. Once a process enters its
critical section, it does not get another turncritical section, it does not get another turn
until a waiting process gets a turn.until a waiting process gets a turn.
SOLUTIONSOLUTION
• In 1981, G.L. Peterson published a simpler algorithm for twoIn 1981, G.L. Peterson published a simpler algorithm for two
process mutual exclusion.process mutual exclusion.
• Boolean flag [2]Boolean flag [2]
int turn;int turn;
while (true)while (true)
{{
flag [i] = true;flag [i] = true;
turn = j;turn = j;
while (flag [j] && turn == j)while (flag [j] && turn == j)
critical section;critical section;
flag [i] = false;flag [i] = false;
remainder section;remainder section;
}}
SOLUTIONSOLUTION
• In 1981, G.L. Peterson published a simpler algorithm for twoIn 1981, G.L. Peterson published a simpler algorithm for two
process mutual exclusion.process mutual exclusion.
• Boolean flag [2]Boolean flag [2]
int turn;int turn;
while (true)while (true)
{{
flag [i] = true;flag [i] = true;
turn = j;turn = j;
while (flag [j] && turn == j)while (flag [j] && turn == j)
critical section;critical section;
flag [i] = false;flag [i] = false;
remainder section;remainder section;
}}
SOLUTION CONTI …SOLUTION CONTI …
• The process share two variablesThe process share two variables
boolean flag [2];boolean flag [2];
int turn;int turn;
• The Flag variable indicate if a process isThe Flag variable indicate if a process is
ready to enter the critical section.ready to enter the critical section.
• Flag [0] = true implies that process p0 isFlag [0] = true implies that process p0 is
ready.ready.
• Turn variable indicates where turn it is toTurn variable indicates where turn it is to
enter the critical section.enter the critical section.
SOLUTION CONTI …SOLUTION CONTI …
• When process p0 sets flag [0] to true, then p1When process p0 sets flag [0] to true, then p1
can not enter its critical section.can not enter its critical section.
• If p1 is already is in critical section, thenIf p1 is already is in critical section, then
flag [i] = true and p0 is blocked fromflag [i] = true and p0 is blocked from
entering its critical section.entering its critical section.
The Critical- Section Problem-R.D.Sivakumar
The Critical- Section Problem-R.D.Sivakumar

More Related Content

Viewers also liked

Lec11 semaphores
Lec11 semaphoresLec11 semaphores
Lec11 semaphoresanandammca
 
Process synchronization in Operating Systems
Process synchronization in Operating SystemsProcess synchronization in Operating Systems
Process synchronization in Operating SystemsRitu Ranjan Shrivastwa
 
ITFT_Semaphores and bounded buffer
ITFT_Semaphores and bounded bufferITFT_Semaphores and bounded buffer
ITFT_Semaphores and bounded bufferSneh Prabha
 
8. mutual exclusion in Distributed Operating Systems
8. mutual exclusion in Distributed Operating Systems8. mutual exclusion in Distributed Operating Systems
8. mutual exclusion in Distributed Operating SystemsDr Sandeep Kumar Poonia
 

Viewers also liked (6)

Lec11 semaphores
Lec11 semaphoresLec11 semaphores
Lec11 semaphores
 
Semaphores
SemaphoresSemaphores
Semaphores
 
6 Synchronisation
6 Synchronisation6 Synchronisation
6 Synchronisation
 
Process synchronization in Operating Systems
Process synchronization in Operating SystemsProcess synchronization in Operating Systems
Process synchronization in Operating Systems
 
ITFT_Semaphores and bounded buffer
ITFT_Semaphores and bounded bufferITFT_Semaphores and bounded buffer
ITFT_Semaphores and bounded buffer
 
8. mutual exclusion in Distributed Operating Systems
8. mutual exclusion in Distributed Operating Systems8. mutual exclusion in Distributed Operating Systems
8. mutual exclusion in Distributed Operating Systems
 

More from Sivakumar R D .

Internet Connections and Its Protocols - R D Sivakumar
Internet Connections and Its Protocols - R D SivakumarInternet Connections and Its Protocols - R D Sivakumar
Internet Connections and Its Protocols - R D SivakumarSivakumar R D .
 
Internet - R D Sivakumar.
Internet - R D Sivakumar.Internet - R D Sivakumar.
Internet - R D Sivakumar.Sivakumar R D .
 
Data Communication - R D Sivakumar
Data Communication - R D SivakumarData Communication - R D Sivakumar
Data Communication - R D SivakumarSivakumar R D .
 
NETWORK SERVICES - R D Sivakumar
NETWORK SERVICES - R D SivakumarNETWORK SERVICES - R D Sivakumar
NETWORK SERVICES - R D SivakumarSivakumar R D .
 
Computer Communications - R D Sivakumar
Computer Communications - R D SivakumarComputer Communications - R D Sivakumar
Computer Communications - R D SivakumarSivakumar R D .
 
Online Data Protection - R D Sivakumar
Online Data Protection - R D SivakumarOnline Data Protection - R D Sivakumar
Online Data Protection - R D SivakumarSivakumar R D .
 
Software Engineering - R.D.Sivakumar
Software Engineering - R.D.SivakumarSoftware Engineering - R.D.Sivakumar
Software Engineering - R.D.SivakumarSivakumar R D .
 
Different Kinds of Internet Protocols - R.D.Sivakumar
Different Kinds of Internet Protocols - R.D.SivakumarDifferent Kinds of Internet Protocols - R.D.Sivakumar
Different Kinds of Internet Protocols - R.D.SivakumarSivakumar R D .
 
Internet - R.D.Sivakumar
Internet - R.D.SivakumarInternet - R.D.Sivakumar
Internet - R.D.SivakumarSivakumar R D .
 
Electronic Publishing Tools for E-Learning - R.D.Sivakumar
Electronic Publishing Tools for E-Learning - R.D.SivakumarElectronic Publishing Tools for E-Learning - R.D.Sivakumar
Electronic Publishing Tools for E-Learning - R.D.SivakumarSivakumar R D .
 
E-learning Packages - R.D.Sivakumar
E-learning Packages - R.D.SivakumarE-learning Packages - R.D.Sivakumar
E-learning Packages - R.D.SivakumarSivakumar R D .
 
Digital Communication - R.D.Sivakumar
Digital Communication - R.D.SivakumarDigital Communication - R.D.Sivakumar
Digital Communication - R.D.SivakumarSivakumar R D .
 
Digigogy in Teaching - R.D.Sivakumar
Digigogy in Teaching - R.D.SivakumarDigigogy in Teaching - R.D.Sivakumar
Digigogy in Teaching - R.D.SivakumarSivakumar R D .
 
Cyber Commerce Technology - R.D.Sivakumar
Cyber Commerce Technology - R.D.SivakumarCyber Commerce Technology - R.D.Sivakumar
Cyber Commerce Technology - R.D.SivakumarSivakumar R D .
 
Video Lesson Creation - R.D.Sivakumar
Video Lesson Creation - R.D.SivakumarVideo Lesson Creation - R.D.Sivakumar
Video Lesson Creation - R.D.SivakumarSivakumar R D .
 
Cognitive and Personal Dimensions of Cyber Learning - R.D.Sivakumar
Cognitive and Personal Dimensions of Cyber Learning - R.D.SivakumarCognitive and Personal Dimensions of Cyber Learning - R.D.Sivakumar
Cognitive and Personal Dimensions of Cyber Learning - R.D.SivakumarSivakumar R D .
 
Innovative Presentation - R.D.Sivakumar
Innovative Presentation - R.D.SivakumarInnovative Presentation - R.D.Sivakumar
Innovative Presentation - R.D.SivakumarSivakumar R D .
 
Open Source in E-Learning - R.D.Sivakumar
Open Source in E-Learning - R.D.SivakumarOpen Source in E-Learning - R.D.Sivakumar
Open Source in E-Learning - R.D.SivakumarSivakumar R D .
 
Tuxpaint - R.D.Sivakumar
Tuxpaint - R.D.SivakumarTuxpaint - R.D.Sivakumar
Tuxpaint - R.D.SivakumarSivakumar R D .
 
Academic Blog Design - R.D.Sivakumar
Academic Blog Design - R.D.SivakumarAcademic Blog Design - R.D.Sivakumar
Academic Blog Design - R.D.SivakumarSivakumar R D .
 

More from Sivakumar R D . (20)

Internet Connections and Its Protocols - R D Sivakumar
Internet Connections and Its Protocols - R D SivakumarInternet Connections and Its Protocols - R D Sivakumar
Internet Connections and Its Protocols - R D Sivakumar
 
Internet - R D Sivakumar.
Internet - R D Sivakumar.Internet - R D Sivakumar.
Internet - R D Sivakumar.
 
Data Communication - R D Sivakumar
Data Communication - R D SivakumarData Communication - R D Sivakumar
Data Communication - R D Sivakumar
 
NETWORK SERVICES - R D Sivakumar
NETWORK SERVICES - R D SivakumarNETWORK SERVICES - R D Sivakumar
NETWORK SERVICES - R D Sivakumar
 
Computer Communications - R D Sivakumar
Computer Communications - R D SivakumarComputer Communications - R D Sivakumar
Computer Communications - R D Sivakumar
 
Online Data Protection - R D Sivakumar
Online Data Protection - R D SivakumarOnline Data Protection - R D Sivakumar
Online Data Protection - R D Sivakumar
 
Software Engineering - R.D.Sivakumar
Software Engineering - R.D.SivakumarSoftware Engineering - R.D.Sivakumar
Software Engineering - R.D.Sivakumar
 
Different Kinds of Internet Protocols - R.D.Sivakumar
Different Kinds of Internet Protocols - R.D.SivakumarDifferent Kinds of Internet Protocols - R.D.Sivakumar
Different Kinds of Internet Protocols - R.D.Sivakumar
 
Internet - R.D.Sivakumar
Internet - R.D.SivakumarInternet - R.D.Sivakumar
Internet - R.D.Sivakumar
 
Electronic Publishing Tools for E-Learning - R.D.Sivakumar
Electronic Publishing Tools for E-Learning - R.D.SivakumarElectronic Publishing Tools for E-Learning - R.D.Sivakumar
Electronic Publishing Tools for E-Learning - R.D.Sivakumar
 
E-learning Packages - R.D.Sivakumar
E-learning Packages - R.D.SivakumarE-learning Packages - R.D.Sivakumar
E-learning Packages - R.D.Sivakumar
 
Digital Communication - R.D.Sivakumar
Digital Communication - R.D.SivakumarDigital Communication - R.D.Sivakumar
Digital Communication - R.D.Sivakumar
 
Digigogy in Teaching - R.D.Sivakumar
Digigogy in Teaching - R.D.SivakumarDigigogy in Teaching - R.D.Sivakumar
Digigogy in Teaching - R.D.Sivakumar
 
Cyber Commerce Technology - R.D.Sivakumar
Cyber Commerce Technology - R.D.SivakumarCyber Commerce Technology - R.D.Sivakumar
Cyber Commerce Technology - R.D.Sivakumar
 
Video Lesson Creation - R.D.Sivakumar
Video Lesson Creation - R.D.SivakumarVideo Lesson Creation - R.D.Sivakumar
Video Lesson Creation - R.D.Sivakumar
 
Cognitive and Personal Dimensions of Cyber Learning - R.D.Sivakumar
Cognitive and Personal Dimensions of Cyber Learning - R.D.SivakumarCognitive and Personal Dimensions of Cyber Learning - R.D.Sivakumar
Cognitive and Personal Dimensions of Cyber Learning - R.D.Sivakumar
 
Innovative Presentation - R.D.Sivakumar
Innovative Presentation - R.D.SivakumarInnovative Presentation - R.D.Sivakumar
Innovative Presentation - R.D.Sivakumar
 
Open Source in E-Learning - R.D.Sivakumar
Open Source in E-Learning - R.D.SivakumarOpen Source in E-Learning - R.D.Sivakumar
Open Source in E-Learning - R.D.Sivakumar
 
Tuxpaint - R.D.Sivakumar
Tuxpaint - R.D.SivakumarTuxpaint - R.D.Sivakumar
Tuxpaint - R.D.Sivakumar
 
Academic Blog Design - R.D.Sivakumar
Academic Blog Design - R.D.SivakumarAcademic Blog Design - R.D.Sivakumar
Academic Blog Design - R.D.Sivakumar
 

Recently uploaded

INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationdeepaannamalai16
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmStan Meyer
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research DiscourseAnita GoswamiGiri
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataBabyAnnMotar
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDhatriParmar
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Projectjordimapav
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvRicaMaeCastro1
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
week 1 cookery 8 fourth - quarter .pptx
week 1 cookery 8  fourth  -  quarter .pptxweek 1 cookery 8  fourth  -  quarter .pptx
week 1 cookery 8 fourth - quarter .pptxJonalynLegaspi2
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWQuiz Club NITW
 
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
Unraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptxUnraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptx
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptxDhatriParmar
 
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...DhatriParmar
 

Recently uploaded (20)

INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentation
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and Film
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research Discourse
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped data
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Project
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
week 1 cookery 8 fourth - quarter .pptx
week 1 cookery 8  fourth  -  quarter .pptxweek 1 cookery 8  fourth  -  quarter .pptx
week 1 cookery 8 fourth - quarter .pptx
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITW
 
prashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Professionprashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Profession
 
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
Unraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptxUnraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptx
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
 
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
 
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptxINCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 

The Critical- Section Problem-R.D.Sivakumar

  • 1. THE CRITICAL-SECTION PROBLEMTHE CRITICAL-SECTION PROBLEM Video Lecture and E-Content Created byVideo Lecture and E-Content Created by R.D.SIVAKUMAR,M.Sc.,M.Phil.,M.Tech.,R.D.SIVAKUMAR,M.Sc.,M.Phil.,M.Tech., Assistant Professor of Computer Science &Assistant Professor of Computer Science & Assistant Professor and Head, Department of M.Com.(CA),Assistant Professor and Head, Department of M.Com.(CA), Ayya Nadar Janaki Ammal College,Ayya Nadar Janaki Ammal College, Sivakasi – 626 124.Sivakasi – 626 124. Mobile: 099440-42243Mobile: 099440-42243 e-mail :e-mail : sivamsccsit@gmail.comsivamsccsit@gmail.com website:website: www.rdsivakumar.blogspot.inwww.rdsivakumar.blogspot.in
  • 2. CRITICAL-SECTIONCRITICAL-SECTION • A section of code (changing commonA section of code (changing common variables, updating a table) is shared withvariables, updating a table) is shared with more than one processes is called criticalmore than one processes is called critical section.section.
  • 3. • All the processes wants to access the sameAll the processes wants to access the same code. But only one process is desired to be incode. But only one process is desired to be in its critical section.its critical section. • A critical section that operates on code.A critical section that operates on code. Example : Railway Reservation SystemExample : Railway Reservation System • A solution to the critical section problem mustA solution to the critical section problem must satisfy the following three requirementssatisfy the following three requirements
  • 4. CRITICAL-SECTION THREE REQUIREMENTSCRITICAL-SECTION THREE REQUIREMENTS • Mutual Exclusion – At a time, only oneMutual Exclusion – At a time, only one process should allow to execute in a criticalprocess should allow to execute in a critical section.section. • Progress – If no process is in critical sectionProgress – If no process is in critical section them quickly decide which one process entersthem quickly decide which one process enters the critical section next.the critical section next. • Bounded Waiting – It is otherwise called asBounded Waiting – It is otherwise called as limit waiting. Once a process enters itslimit waiting. Once a process enters its critical section, it does not get another turncritical section, it does not get another turn until a waiting process gets a turn.until a waiting process gets a turn.
  • 5. SOLUTIONSOLUTION • In 1981, G.L. Peterson published a simpler algorithm for twoIn 1981, G.L. Peterson published a simpler algorithm for two process mutual exclusion.process mutual exclusion. • Boolean flag [2]Boolean flag [2] int turn;int turn; while (true)while (true) {{ flag [i] = true;flag [i] = true; turn = j;turn = j; while (flag [j] && turn == j)while (flag [j] && turn == j) critical section;critical section; flag [i] = false;flag [i] = false; remainder section;remainder section; }}
  • 6. SOLUTIONSOLUTION • In 1981, G.L. Peterson published a simpler algorithm for twoIn 1981, G.L. Peterson published a simpler algorithm for two process mutual exclusion.process mutual exclusion. • Boolean flag [2]Boolean flag [2] int turn;int turn; while (true)while (true) {{ flag [i] = true;flag [i] = true; turn = j;turn = j; while (flag [j] && turn == j)while (flag [j] && turn == j) critical section;critical section; flag [i] = false;flag [i] = false; remainder section;remainder section; }}
  • 7. SOLUTION CONTI …SOLUTION CONTI … • The process share two variablesThe process share two variables boolean flag [2];boolean flag [2]; int turn;int turn; • The Flag variable indicate if a process isThe Flag variable indicate if a process is ready to enter the critical section.ready to enter the critical section. • Flag [0] = true implies that process p0 isFlag [0] = true implies that process p0 is ready.ready. • Turn variable indicates where turn it is toTurn variable indicates where turn it is to enter the critical section.enter the critical section.
  • 8. SOLUTION CONTI …SOLUTION CONTI … • When process p0 sets flag [0] to true, then p1When process p0 sets flag [0] to true, then p1 can not enter its critical section.can not enter its critical section. • If p1 is already is in critical section, thenIf p1 is already is in critical section, then flag [i] = true and p0 is blocked fromflag [i] = true and p0 is blocked from entering its critical section.entering its critical section.