SlideShare a Scribd company logo
Process Synchronization
Process Synchronization
• Process Synchronization means sharing system resources
by processes in a such a way that, Concurrent access to shared data is
handled thereby minimizing the chance of inconsistent data.
• Process Synchronization was introduced to handle problems that arose
while multiple process executions.
• Examples of Process Synchronization , Printer are a shared resource
which multiple process can access and use but can not use it at the
same time. If they try to access at same time deadlock occurs.
Process Synchronization Example
a=10;
Process()
{
Read variable a;
a++;
Write variable a;
}
• Output Case 1: p0 -> 11 & p1 -> 12
• Output Case 2: p0 -> 11 & p1-> 11
Critical Section
• The area through process execution through which a process try to
access a shared resource is called critical section.
Critical Section Environment
• A Critical Section Environment contains:
• Entry Section Code requesting entry into the critical section.
• Critical Section Code in which only one process can execute at any one
time.
• Exit Section The end of the critical section, releasing or allowing others in.
• Remainder Section Rest of the code AFTER the critical section.
Critical Section Condition
• A process has to fulfil three condition before entering into critical
section.
1. Mutual Exclusive
2. Progress
3. Bounded wait.
In above condition first two are mandatory and a process must has to fulfil these
conditions before accessing critical section.
Mutual Exclusive
• Mutual Exclusion: No more than one process can execute in its critical
section at one time.
P0 P1
while(1){ while(1){
while(turn!=0); while(turn!=1);
//Critical Section. //Critical Section
turn=1; turn=0;
//Remainder Section //Remainder Section
} }
Progress
• If no one is in the critical section and someone wants in, then those
processes not in their remainder section must be able to decide in a finite
time who should go in.
P0 P1
while(1){ while(1){
flag[0]=T flag[1]=T
while(flag[1]); while(flag[0]);
//Critical Section. //Critical Section
flag[0]=F; flag[1]=F;
//Remainder Section //Remainder Section
} }
Bounded Wait
• All requesters must eventually be let into the critical section
• After a process makes a request for getting into its critical section,
there is a limit for how many other processes can get into their critical
section, before this process's request is granted. So after the limit is
reached, system must grant the process permission to get into its
critical section.
Peterson Solution
• Peterson's algorithm is used for mutual exclusion and allows two
processes to share a single-use resource without conflict.
• Peterson's formula originally worked only with two processes, but has
since been generalized for more than two.
• To handle the problem of Critical Section (CS), Peterson gave an
algorithm.
• Mutual exclusion, no progress two essential criteria used to solve the
critical section problem when using the algorithm.
Peterson Solution Algorithm
P0 P1
while(1){ while(1){
flag[0]=T; flag[1]=T;
turn=1; turn=0;
while(turn==1 && flag[1]); while(turn==0 && flag[0]);
//Critical Section. //Critical Section
flag[0]=F; flag[1]=F;
//Remainder Section //Remainder Section
} }
Semaphore
• A semaphore is an integer variable “int s”, that apart from
introduction, is accessed only through two standard atomic
operations.
• FORMAT:
do{
wait ( S );
CRITICAL SECTION
signal( S );
REMAINDER
}while(T)
Semaphore
• Wait : decrement the value of its argument S as soon as it would become
non-negative.
wait(s){
while(s<=0);
s--;}
• Signal : increment the value of its argument, S as an individual operation.
signal(s){
s++;
}
Example
do{
wait ( S );
CRITICAL SECTION
signal( S );
REMAINDER
}while(T);
wait(s){ signal(s){
while(s<=0); s++;
s--;} }
Fuck You Guys!!

More Related Content

What's hot

Deadlock detection & prevention
Deadlock detection & preventionDeadlock detection & prevention
Deadlock detection & preventionIkhtiarUddinShaHin
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OSvampugani
 
Os case study word
Os case study wordOs case study word
Os case study wordDhol Yash
 
Operating Systems: Process Scheduling
Operating Systems: Process SchedulingOperating Systems: Process Scheduling
Operating Systems: Process SchedulingDamian T. Gordon
 
Operating Systems - Process Synchronization and Deadlocks
Operating Systems - Process Synchronization and DeadlocksOperating Systems - Process Synchronization and Deadlocks
Operating Systems - Process Synchronization and DeadlocksMukesh Chinta
 
Os unit 3 , process management
Os unit 3 , process managementOs unit 3 , process management
Os unit 3 , process managementArnav Chowdhury
 
Deadlock Avoidance - OS
Deadlock Avoidance - OSDeadlock Avoidance - OS
Deadlock Avoidance - OSMsAnita2
 
Methods for handling deadlocks
Methods for handling deadlocksMethods for handling deadlocks
Methods for handling deadlocksA. S. M. Shafi
 
Understanding deadlocks in operating system
Understanding deadlocks in operating systemUnderstanding deadlocks in operating system
Understanding deadlocks in operating systemSanjeevlu Buggargani
 
Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating systemSara Ali
 

What's hot (20)

Deadlock
DeadlockDeadlock
Deadlock
 
Operating System: Deadlock
Operating System: DeadlockOperating System: Deadlock
Operating System: Deadlock
 
Deadlock detection & prevention
Deadlock detection & preventionDeadlock detection & prevention
Deadlock detection & prevention
 
Concurrency
ConcurrencyConcurrency
Concurrency
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OS
 
Os case study word
Os case study wordOs case study word
Os case study word
 
Operating Systems: Process Scheduling
Operating Systems: Process SchedulingOperating Systems: Process Scheduling
Operating Systems: Process Scheduling
 
Swapping | Computer Science
Swapping | Computer ScienceSwapping | Computer Science
Swapping | Computer Science
 
Operating Systems - Process Synchronization and Deadlocks
Operating Systems - Process Synchronization and DeadlocksOperating Systems - Process Synchronization and Deadlocks
Operating Systems - Process Synchronization and Deadlocks
 
Chapter 7 - Deadlocks
Chapter 7 - DeadlocksChapter 7 - Deadlocks
Chapter 7 - Deadlocks
 
operating system structure
operating system structureoperating system structure
operating system structure
 
Os unit 3 , process management
Os unit 3 , process managementOs unit 3 , process management
Os unit 3 , process management
 
Lecture 2 process
Lecture 2   processLecture 2   process
Lecture 2 process
 
Deadlock Avoidance - OS
Deadlock Avoidance - OSDeadlock Avoidance - OS
Deadlock Avoidance - OS
 
Methods for handling deadlocks
Methods for handling deadlocksMethods for handling deadlocks
Methods for handling deadlocks
 
Operating system critical section
Operating system   critical sectionOperating system   critical section
Operating system critical section
 
Understanding deadlocks in operating system
Understanding deadlocks in operating systemUnderstanding deadlocks in operating system
Understanding deadlocks in operating system
 
7 Deadlocks
7 Deadlocks7 Deadlocks
7 Deadlocks
 
Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating system
 
System call
System callSystem call
System call
 

Similar to Process synchronization

Mutual Exclusion using Peterson's Algorithm
Mutual Exclusion using Peterson's AlgorithmMutual Exclusion using Peterson's Algorithm
Mutual Exclusion using Peterson's AlgorithmSouvik Roy
 
Critical Section Problem.pptx
Critical Section Problem.pptxCritical Section Problem.pptx
Critical Section Problem.pptxAbuBakkarShayan
 
Operating system 23 process synchronization
Operating system 23 process synchronizationOperating system 23 process synchronization
Operating system 23 process synchronizationVaibhav Khanna
 
CSI-503 - 4. Process synchronization
CSI-503 - 4. Process synchronizationCSI-503 - 4. Process synchronization
CSI-503 - 4. Process synchronizationghayour abbas
 
Process management in Operating System_Unit-2
Process management in Operating System_Unit-2Process management in Operating System_Unit-2
Process management in Operating System_Unit-2mohanaps
 
Coordination and Agreement .ppt
Coordination and Agreement .pptCoordination and Agreement .ppt
Coordination and Agreement .pptSOURAVKUMAR723356
 
Lecture 5- Process Synchonization_revised.pdf
Lecture 5- Process Synchonization_revised.pdfLecture 5- Process Synchonization_revised.pdf
Lecture 5- Process Synchonization_revised.pdfAmanuelmergia
 
criticalsectionproblem-160905215747.pdf
criticalsectionproblem-160905215747.pdfcriticalsectionproblem-160905215747.pdf
criticalsectionproblem-160905215747.pdfBhanuCharan9
 
Critical section problem in operating system.
Critical section problem in operating system.Critical section problem in operating system.
Critical section problem in operating system.MOHIT DADU
 
Lecture 5- Process Synchronization (1).pptx
Lecture 5- Process Synchronization (1).pptxLecture 5- Process Synchronization (1).pptx
Lecture 5- Process Synchronization (1).pptxAmanuelmergia
 
Intro Basic of OS .ppt
Intro Basic of OS .pptIntro Basic of OS .ppt
Intro Basic of OS .pptVarsha506533
 

Similar to Process synchronization (20)

Mutual Exclusion using Peterson's Algorithm
Mutual Exclusion using Peterson's AlgorithmMutual Exclusion using Peterson's Algorithm
Mutual Exclusion using Peterson's Algorithm
 
Critical Section Problem.pptx
Critical Section Problem.pptxCritical Section Problem.pptx
Critical Section Problem.pptx
 
Synchronization
SynchronizationSynchronization
Synchronization
 
Operating system 23 process synchronization
Operating system 23 process synchronizationOperating system 23 process synchronization
Operating system 23 process synchronization
 
process syn.ppt
process syn.pptprocess syn.ppt
process syn.ppt
 
CSI-503 - 4. Process synchronization
CSI-503 - 4. Process synchronizationCSI-503 - 4. Process synchronization
CSI-503 - 4. Process synchronization
 
Process management in Operating System_Unit-2
Process management in Operating System_Unit-2Process management in Operating System_Unit-2
Process management in Operating System_Unit-2
 
Coordination and Agreement .ppt
Coordination and Agreement .pptCoordination and Agreement .ppt
Coordination and Agreement .ppt
 
Critical section operating system
Critical section  operating systemCritical section  operating system
Critical section operating system
 
Lecture 5- Process Synchonization_revised.pdf
Lecture 5- Process Synchonization_revised.pdfLecture 5- Process Synchonization_revised.pdf
Lecture 5- Process Synchonization_revised.pdf
 
criticalsectionproblem-160905215747.pdf
criticalsectionproblem-160905215747.pdfcriticalsectionproblem-160905215747.pdf
criticalsectionproblem-160905215747.pdf
 
Critical section problem in operating system.
Critical section problem in operating system.Critical section problem in operating system.
Critical section problem in operating system.
 
OS UNIT3.pptx
OS UNIT3.pptxOS UNIT3.pptx
OS UNIT3.pptx
 
Lecture 5- Process Synchronization (1).pptx
Lecture 5- Process Synchronization (1).pptxLecture 5- Process Synchronization (1).pptx
Lecture 5- Process Synchronization (1).pptx
 
Lecture 5 inter process communication
Lecture 5 inter process communicationLecture 5 inter process communication
Lecture 5 inter process communication
 
Cs problem [repaired]
Cs problem [repaired]Cs problem [repaired]
Cs problem [repaired]
 
Ch5 process synchronization
Ch5   process synchronizationCh5   process synchronization
Ch5 process synchronization
 
Process coordination
Process coordinationProcess coordination
Process coordination
 
Mutual exclusion and sync
Mutual exclusion and syncMutual exclusion and sync
Mutual exclusion and sync
 
Intro Basic of OS .ppt
Intro Basic of OS .pptIntro Basic of OS .ppt
Intro Basic of OS .ppt
 

Recently uploaded

Application of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesApplication of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesRased Khan
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePedroFerreira53928
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleCeline George
 
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...Sayali Powar
 
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...Denish Jangid
 
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptBasic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptSourabh Kumar
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxRaedMohamed3
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...Nguyen Thanh Tu Collection
 
The Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational ResourcesThe Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational Resourcesaileywriter
 
NLC-2024-Orientation-for-RO-SDO (1).pptx
NLC-2024-Orientation-for-RO-SDO (1).pptxNLC-2024-Orientation-for-RO-SDO (1).pptx
NLC-2024-Orientation-for-RO-SDO (1).pptxssuserbdd3e8
 
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptxSolid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptxDenish Jangid
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfQucHHunhnh
 
Salient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxSalient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxakshayaramakrishnan21
 
Advances in production technology of Grapes.pdf
Advances in production technology of Grapes.pdfAdvances in production technology of Grapes.pdf
Advances in production technology of Grapes.pdfDr. M. Kumaresan Hort.
 
Gyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptxGyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptxShibin Azad
 
2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptxmansk2
 

Recently uploaded (20)

Application of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesApplication of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matrices
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
 
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptBasic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
 
The Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational ResourcesThe Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational Resources
 
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
Operations Management - Book1.p  - Dr. Abdulfatah A. SalemOperations Management - Book1.p  - Dr. Abdulfatah A. Salem
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
 
NLC-2024-Orientation-for-RO-SDO (1).pptx
NLC-2024-Orientation-for-RO-SDO (1).pptxNLC-2024-Orientation-for-RO-SDO (1).pptx
NLC-2024-Orientation-for-RO-SDO (1).pptx
 
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptxSolid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
 
NCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdfNCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdf
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
 
Salient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxSalient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptx
 
Advances in production technology of Grapes.pdf
Advances in production technology of Grapes.pdfAdvances in production technology of Grapes.pdf
Advances in production technology of Grapes.pdf
 
Gyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptxGyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptx
 
2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx
 

Process synchronization

  • 2. Process Synchronization • Process Synchronization means sharing system resources by processes in a such a way that, Concurrent access to shared data is handled thereby minimizing the chance of inconsistent data. • Process Synchronization was introduced to handle problems that arose while multiple process executions. • Examples of Process Synchronization , Printer are a shared resource which multiple process can access and use but can not use it at the same time. If they try to access at same time deadlock occurs.
  • 3. Process Synchronization Example a=10; Process() { Read variable a; a++; Write variable a; } • Output Case 1: p0 -> 11 & p1 -> 12 • Output Case 2: p0 -> 11 & p1-> 11
  • 4. Critical Section • The area through process execution through which a process try to access a shared resource is called critical section.
  • 5. Critical Section Environment • A Critical Section Environment contains: • Entry Section Code requesting entry into the critical section. • Critical Section Code in which only one process can execute at any one time. • Exit Section The end of the critical section, releasing or allowing others in. • Remainder Section Rest of the code AFTER the critical section.
  • 6. Critical Section Condition • A process has to fulfil three condition before entering into critical section. 1. Mutual Exclusive 2. Progress 3. Bounded wait. In above condition first two are mandatory and a process must has to fulfil these conditions before accessing critical section.
  • 7. Mutual Exclusive • Mutual Exclusion: No more than one process can execute in its critical section at one time. P0 P1 while(1){ while(1){ while(turn!=0); while(turn!=1); //Critical Section. //Critical Section turn=1; turn=0; //Remainder Section //Remainder Section } }
  • 8. Progress • If no one is in the critical section and someone wants in, then those processes not in their remainder section must be able to decide in a finite time who should go in. P0 P1 while(1){ while(1){ flag[0]=T flag[1]=T while(flag[1]); while(flag[0]); //Critical Section. //Critical Section flag[0]=F; flag[1]=F; //Remainder Section //Remainder Section } }
  • 9. Bounded Wait • All requesters must eventually be let into the critical section • After a process makes a request for getting into its critical section, there is a limit for how many other processes can get into their critical section, before this process's request is granted. So after the limit is reached, system must grant the process permission to get into its critical section.
  • 10. Peterson Solution • Peterson's algorithm is used for mutual exclusion and allows two processes to share a single-use resource without conflict. • Peterson's formula originally worked only with two processes, but has since been generalized for more than two. • To handle the problem of Critical Section (CS), Peterson gave an algorithm. • Mutual exclusion, no progress two essential criteria used to solve the critical section problem when using the algorithm.
  • 11. Peterson Solution Algorithm P0 P1 while(1){ while(1){ flag[0]=T; flag[1]=T; turn=1; turn=0; while(turn==1 && flag[1]); while(turn==0 && flag[0]); //Critical Section. //Critical Section flag[0]=F; flag[1]=F; //Remainder Section //Remainder Section } }
  • 12. Semaphore • A semaphore is an integer variable “int s”, that apart from introduction, is accessed only through two standard atomic operations. • FORMAT: do{ wait ( S ); CRITICAL SECTION signal( S ); REMAINDER }while(T)
  • 13. Semaphore • Wait : decrement the value of its argument S as soon as it would become non-negative. wait(s){ while(s<=0); s--;} • Signal : increment the value of its argument, S as an individual operation. signal(s){ s++; }
  • 14. Example do{ wait ( S ); CRITICAL SECTION signal( S ); REMAINDER }while(T); wait(s){ signal(s){ while(s<=0); s++; s--;} }