SlideShare a Scribd company logo
1 of 17
Process
Synchronization
Ramsha Ghaffar
Syed Hassan Ali Hashmi
Introduction
What is 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.
Maintaining data consistency demands mechanisms to ensure synchronized execution of
cooperating processes.
Introduction
On the basis of synchronization:
Processes are categorized as one of the following two types:
• Independent Process : Execution of one process does not affects the execution of other
processes.
• Cooperative Process : Execution of one process affects the execution of other processes.
Process synchronization problem arises in the case of Cooperative process also because resources
are shared in Cooperative processes.
Critical Section
Problem
Critical section is a code segment that can be accessed
by only one process at a time.
Critical section contains shared variables which need
to be synchronized to maintain consistency of data
variables.
In the entry section, the process requests for entry
in the Critical Section.
Critical Section
Solution To Problem
A solution to the critical section problem must satisfy the following three conditions:
• Mutual Exclusion : If a process is executing in its critical section, then no other process is
allowed to execute in the critical section.
• Progress : If no process is in the critical section, then no other process from outside can block it
from entering the critical section.
• 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.
Peterson’s Solution
Peterson’s Solution is a classical software based
solution to the critical section problem.
In Peterson’s solution, we have two shared variables:
• boolean flag[i] :Initialized to FALSE, initially no one is
interested in entering the critical section
• int turn : The process whose turn is to enter the
critical section.
Peterson’s Solution
Peterson’s Solution preserves all three conditions
• Mutual Exclusion is assured as only one process can access the critical section at any time.
• Progress is also assured, as a process outside the critical section does not blocks other
processes from entering the critical section.
• Bounded Waiting is preserved as every process gets a fair chance.
Process Synchronization
Synchronization Hardware
Many systems provide hardware support for critical section code. The critical section problem
could be solved easily in a single-processor environment if we could disallow interrupts to occur
while a shared variable or resource is being modified.
In this manner, we could be sure that the current sequence of instructions would be allowed to
execute in order without pre-emption. Unfortunately, this solution is not feasible in a
multiprocessor environment.
Disabling interrupt on a multiprocessor environment can be time consuming as the message is
passed to all the processors.
This message transmission lag, delays entry of threads into critical section and the system
efficiency decreases.
Mutex Locks
As the synchronization hardware solution is not easy to
implement for everyone
A strict software approach called Mutex Locks was introduced. In this approach, in the entry
section of code, a LOCK is acquired over the critical resources modified and used inside critical
section, and in the exit section that LOCK is released.
As the resource is locked while a process executes its critical section hence no other process can
access it.
Semaphores
Introduction
In 1965, Dijkstra proposed a new and very significant technique for managing concurrent processes
by using the value of a simple integer variable to synchronize the progress of interacting processes.
This integer variable is called semaphore. So it is basically a synchronizing tool and is accessed only
through two low standard atomic operations, wait and signal designated by P(S) and V(S)
respectively.
In very simple words, semaphore is a variable which can hold only a non-negative Integer value,
shared between all the threads, with operations wait and signal
P(S): if S ≥ 1
then S := S - 1
else
<block and enqueue the process>;
V(S): if <some process is blocked on the queue>
then <unblock a process>
else
S := S + 1;
Semaphores
The classical definitions of wait and signal are:
• Wait: Decrements the value of its argument S, as soon as it would become non-
negative(greater than or equal to 1).
• Signal: Increments the value of its argument S, as there is no more process blocked on the
queue.
Semaphores
Properties of Semaphores
• It's simple and always have a non-negative Integer value.
• Works with many processes.
• Can have many different critical sections with different semaphores.
• Each critical section has unique access semaphores.
• Can permit multiple processes into the critical section at once, if desirable.
Semaphores
Types of Semaphores
• Binary Semaphore: It is a special form of semaphore used for implementing
mutual exclusion, hence it is often called a Mutex. A binary semaphore is
initialized to 1 and only takes the values 0 and 1 during execution of a program.
• Counting Semaphores: These are used to implement bounded concurrency.
Semaphores
Example of Use
Shared var mutex: semaphore = 1;
Process i
begin
.
.
P(mutex);
execute CS;
V(mutex);
.
.
End;
Semaphores
Limitations of Semaphores
• Priority Inversion is a big limitation of semaphores.
• Their use is not enforced, but is by convention only.
• With improper use, a process may block indefinitely. Such a situation is called Deadlock. We
will be studying deadlocks in details in coming lessons.
For Self Studies
References
• Abraham Silberschatz, Greg Gagne, and Peter Baer Galvin, "Operating System Concepts,
Ninth Edition ", Chapter 5
• https://www.geeksforgeeks.org/process-synchronization-set-1/
• https://en.wikipedia.org/wiki/Synchronization_(computer_science)
Process synchronization

More Related Content

What's hot

Process management in os
Process management in osProcess management in os
Process management in osMiong Lazaro
 
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
 
DeadLock in Operating-Systems
DeadLock in Operating-SystemsDeadLock in Operating-Systems
DeadLock in Operating-SystemsVenkata Sreeram
 
Semophores and it's types
Semophores and it's typesSemophores and it's types
Semophores and it's typesNishant Joshi
 
Process scheduling
Process schedulingProcess scheduling
Process schedulingRiya Choudhary
 
Deadlock Prevention
Deadlock PreventionDeadlock Prevention
Deadlock Preventionprachi mewara
 
Inter Process Communication
Inter Process CommunicationInter Process Communication
Inter Process CommunicationAdeel Rasheed
 
Operating System-Process Scheduling
Operating System-Process SchedulingOperating System-Process Scheduling
Operating System-Process SchedulingShipra Swati
 
Chapter 11 - File System Implementation
Chapter 11 - File System ImplementationChapter 11 - File System Implementation
Chapter 11 - File System ImplementationWayne Jones Jnr
 
CPU Scheduling in OS Presentation
CPU Scheduling in OS  PresentationCPU Scheduling in OS  Presentation
CPU Scheduling in OS Presentationusmankiyani1
 
Scheduling algorithms
Scheduling algorithmsScheduling algorithms
Scheduling algorithmsChankey Pathak
 
First-Come-First-Serve (FCFS)
First-Come-First-Serve (FCFS)First-Come-First-Serve (FCFS)
First-Come-First-Serve (FCFS)nikeAthena
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OSvampugani
 
Process in operating system
Process in operating systemProcess in operating system
Process in operating systemChetan Mahawar
 
Operating System: Deadlock
Operating System: DeadlockOperating System: Deadlock
Operating System: DeadlockInteX Research Lab
 
Semaphores
SemaphoresSemaphores
SemaphoresMohd Arif
 
Operating systems system structures
Operating systems   system structuresOperating systems   system structures
Operating systems system structuresMukesh Chinta
 

What's hot (20)

Process management in os
Process management in osProcess management in os
Process management in os
 
Deadlock ppt
Deadlock ppt Deadlock ppt
Deadlock ppt
 
Critical section problem in operating system.
Critical section problem in operating system.Critical section problem in operating system.
Critical section problem in operating system.
 
DeadLock in Operating-Systems
DeadLock in Operating-SystemsDeadLock in Operating-Systems
DeadLock in Operating-Systems
 
Semophores and it's types
Semophores and it's typesSemophores and it's types
Semophores and it's types
 
Process scheduling
Process schedulingProcess scheduling
Process scheduling
 
Deadlock Prevention
Deadlock PreventionDeadlock Prevention
Deadlock Prevention
 
Inter Process Communication
Inter Process CommunicationInter Process Communication
Inter Process Communication
 
Operating System-Process Scheduling
Operating System-Process SchedulingOperating System-Process Scheduling
Operating System-Process Scheduling
 
Chapter 11 - File System Implementation
Chapter 11 - File System ImplementationChapter 11 - File System Implementation
Chapter 11 - File System Implementation
 
CPU Scheduling in OS Presentation
CPU Scheduling in OS  PresentationCPU Scheduling in OS  Presentation
CPU Scheduling in OS Presentation
 
Scheduling algorithms
Scheduling algorithmsScheduling algorithms
Scheduling algorithms
 
First-Come-First-Serve (FCFS)
First-Come-First-Serve (FCFS)First-Come-First-Serve (FCFS)
First-Come-First-Serve (FCFS)
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OS
 
Process in operating system
Process in operating systemProcess in operating system
Process in operating system
 
Operating System: Deadlock
Operating System: DeadlockOperating System: Deadlock
Operating System: Deadlock
 
Semaphores
SemaphoresSemaphores
Semaphores
 
System calls
System callsSystem calls
System calls
 
Operating systems system structures
Operating systems   system structuresOperating systems   system structures
Operating systems system structures
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
 

Similar to Process synchronization

Process synchronization
Process synchronizationProcess synchronization
Process synchronizationlodhran-hayat
 
Operating system 27 semaphores
Operating system 27 semaphoresOperating system 27 semaphores
Operating system 27 semaphoresVaibhav Khanna
 
CSI-503 - 4. Process synchronization
CSI-503 - 4. Process synchronizationCSI-503 - 4. Process synchronization
CSI-503 - 4. Process synchronizationghayour abbas
 
Lecture 5 inter process communication
Lecture 5 inter process communicationLecture 5 inter process communication
Lecture 5 inter process communicationKumbirai Junior Muzavazi
 
critical section problem.pptx
critical section problem.pptxcritical section problem.pptx
critical section problem.pptxvtu19163
 
Concurrency: Mutual Exclusion and Synchronization
Concurrency: Mutual Exclusion and SynchronizationConcurrency: Mutual Exclusion and Synchronization
Concurrency: Mutual Exclusion and SynchronizationAnas Ebrahim
 
Critical section operating system
Critical section  operating systemCritical section  operating system
Critical section operating systemMuhammad Baqar Kazmi
 
Lecture 9 - Process Synchronization.pptx
Lecture 9 - Process Synchronization.pptxLecture 9 - Process Synchronization.pptx
Lecture 9 - Process Synchronization.pptxEhteshamulIslam1
 
Concurrency Control in Distributed Systems.pptx
Concurrency Control in Distributed Systems.pptxConcurrency Control in Distributed Systems.pptx
Concurrency Control in Distributed Systems.pptxMArshad35
 
dos mutual exclusion algos
dos mutual exclusion algosdos mutual exclusion algos
dos mutual exclusion algosAkhil Sharma
 
Process Synchronization -1.ppt
Process Synchronization -1.pptProcess Synchronization -1.ppt
Process Synchronization -1.pptjayverma27
 
Inter process communication
Inter process communicationInter process communication
Inter process communicationGift Kaliza
 
Lecture 5- Process Synchonization_revised.pdf
Lecture 5- Process Synchonization_revised.pdfLecture 5- Process Synchonization_revised.pdf
Lecture 5- Process Synchonization_revised.pdfAmanuelmergia
 
Operating System- INTERPROCESS COMMUNICATION.docx
Operating System- INTERPROCESS COMMUNICATION.docxOperating System- INTERPROCESS COMMUNICATION.docx
Operating System- INTERPROCESS COMMUNICATION.docxminaltmv
 
criticalsectionproblem-160905215747.pdf
criticalsectionproblem-160905215747.pdfcriticalsectionproblem-160905215747.pdf
criticalsectionproblem-160905215747.pdfBhanuCharan9
 
Lecture 5- Process Synchronization (1).pptx
Lecture 5- Process Synchronization (1).pptxLecture 5- Process Synchronization (1).pptx
Lecture 5- Process Synchronization (1).pptxAmanuelmergia
 
Chapter05 new
Chapter05 newChapter05 new
Chapter05 newvmummaneni
 
Advanced python
Advanced pythonAdvanced python
Advanced pythonNovita Sari
 

Similar to Process synchronization (20)

Process synchronization
Process synchronizationProcess synchronization
Process synchronization
 
Operating system 27 semaphores
Operating system 27 semaphoresOperating system 27 semaphores
Operating system 27 semaphores
 
Process coordination
Process coordinationProcess coordination
Process coordination
 
CSI-503 - 4. Process synchronization
CSI-503 - 4. Process synchronizationCSI-503 - 4. Process synchronization
CSI-503 - 4. Process synchronization
 
Lecture 5 inter process communication
Lecture 5 inter process communicationLecture 5 inter process communication
Lecture 5 inter process communication
 
critical section problem.pptx
critical section problem.pptxcritical section problem.pptx
critical section problem.pptx
 
Concurrency: Mutual Exclusion and Synchronization
Concurrency: Mutual Exclusion and SynchronizationConcurrency: Mutual Exclusion and Synchronization
Concurrency: Mutual Exclusion and Synchronization
 
Critical section operating system
Critical section  operating systemCritical section  operating system
Critical section operating system
 
Lecture 9 - Process Synchronization.pptx
Lecture 9 - Process Synchronization.pptxLecture 9 - Process Synchronization.pptx
Lecture 9 - Process Synchronization.pptx
 
Concurrency Control in Distributed Systems.pptx
Concurrency Control in Distributed Systems.pptxConcurrency Control in Distributed Systems.pptx
Concurrency Control in Distributed Systems.pptx
 
dos mutual exclusion algos
dos mutual exclusion algosdos mutual exclusion algos
dos mutual exclusion algos
 
Process Synchronization -1.ppt
Process Synchronization -1.pptProcess Synchronization -1.ppt
Process Synchronization -1.ppt
 
Inter process communication
Inter process communicationInter process communication
Inter process communication
 
Lecture 5- Process Synchonization_revised.pdf
Lecture 5- Process Synchonization_revised.pdfLecture 5- Process Synchonization_revised.pdf
Lecture 5- Process Synchonization_revised.pdf
 
Operating System- INTERPROCESS COMMUNICATION.docx
Operating System- INTERPROCESS COMMUNICATION.docxOperating System- INTERPROCESS COMMUNICATION.docx
Operating System- INTERPROCESS COMMUNICATION.docx
 
criticalsectionproblem-160905215747.pdf
criticalsectionproblem-160905215747.pdfcriticalsectionproblem-160905215747.pdf
criticalsectionproblem-160905215747.pdf
 
Lecture 5- Process Synchronization (1).pptx
Lecture 5- Process Synchronization (1).pptxLecture 5- Process Synchronization (1).pptx
Lecture 5- Process Synchronization (1).pptx
 
OS 6.pptx
OS 6.pptxOS 6.pptx
OS 6.pptx
 
Chapter05 new
Chapter05 newChapter05 new
Chapter05 new
 
Advanced python
Advanced pythonAdvanced python
Advanced python
 

More from Syed Hassan Ali

COCOMO Model in software project management
COCOMO Model in software project managementCOCOMO Model in software project management
COCOMO Model in software project managementSyed Hassan Ali
 
Resource Allocation In Software Project Management
Resource Allocation In Software Project ManagementResource Allocation In Software Project Management
Resource Allocation In Software Project ManagementSyed Hassan Ali
 
Accountability And Auditing In Professional Practice
Accountability And Auditing In Professional PracticeAccountability And Auditing In Professional Practice
Accountability And Auditing In Professional PracticeSyed Hassan Ali
 
Use Case Modeling In UML
Use Case Modeling In UMLUse Case Modeling In UML
Use Case Modeling In UMLSyed Hassan Ali
 
Software Generic Design Process.
Software Generic Design Process.Software Generic Design Process.
Software Generic Design Process.Syed Hassan Ali
 
Structured Query Language (SQL)
Structured Query Language (SQL)Structured Query Language (SQL)
Structured Query Language (SQL)Syed Hassan Ali
 
Grasp patterns and its types
Grasp patterns and its typesGrasp patterns and its types
Grasp patterns and its typesSyed Hassan Ali
 

More from Syed Hassan Ali (7)

COCOMO Model in software project management
COCOMO Model in software project managementCOCOMO Model in software project management
COCOMO Model in software project management
 
Resource Allocation In Software Project Management
Resource Allocation In Software Project ManagementResource Allocation In Software Project Management
Resource Allocation In Software Project Management
 
Accountability And Auditing In Professional Practice
Accountability And Auditing In Professional PracticeAccountability And Auditing In Professional Practice
Accountability And Auditing In Professional Practice
 
Use Case Modeling In UML
Use Case Modeling In UMLUse Case Modeling In UML
Use Case Modeling In UML
 
Software Generic Design Process.
Software Generic Design Process.Software Generic Design Process.
Software Generic Design Process.
 
Structured Query Language (SQL)
Structured Query Language (SQL)Structured Query Language (SQL)
Structured Query Language (SQL)
 
Grasp patterns and its types
Grasp patterns and its typesGrasp patterns and its types
Grasp patterns and its types
 

Recently uploaded

AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationAadityaSharma884161
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayMakMakNepo
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxsqpmdrvczh
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 

Recently uploaded (20)

AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint Presentation
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up Friday
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptx
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 

Process synchronization

  • 2. Introduction What is 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. Maintaining data consistency demands mechanisms to ensure synchronized execution of cooperating processes.
  • 3. Introduction On the basis of synchronization: Processes are categorized as one of the following two types: • Independent Process : Execution of one process does not affects the execution of other processes. • Cooperative Process : Execution of one process affects the execution of other processes. Process synchronization problem arises in the case of Cooperative process also because resources are shared in Cooperative processes.
  • 4. Critical Section Problem Critical section is a code segment that can be accessed by only one process at a time. Critical section contains shared variables which need to be synchronized to maintain consistency of data variables. In the entry section, the process requests for entry in the Critical Section.
  • 5. Critical Section Solution To Problem A solution to the critical section problem must satisfy the following three conditions: • Mutual Exclusion : If a process is executing in its critical section, then no other process is allowed to execute in the critical section. • Progress : If no process is in the critical section, then no other process from outside can block it from entering the critical section. • 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.
  • 6. Peterson’s Solution Peterson’s Solution is a classical software based solution to the critical section problem. In Peterson’s solution, we have two shared variables: • boolean flag[i] :Initialized to FALSE, initially no one is interested in entering the critical section • int turn : The process whose turn is to enter the critical section.
  • 7. Peterson’s Solution Peterson’s Solution preserves all three conditions • Mutual Exclusion is assured as only one process can access the critical section at any time. • Progress is also assured, as a process outside the critical section does not blocks other processes from entering the critical section. • Bounded Waiting is preserved as every process gets a fair chance.
  • 8. Process Synchronization Synchronization Hardware Many systems provide hardware support for critical section code. The critical section problem could be solved easily in a single-processor environment if we could disallow interrupts to occur while a shared variable or resource is being modified. In this manner, we could be sure that the current sequence of instructions would be allowed to execute in order without pre-emption. Unfortunately, this solution is not feasible in a multiprocessor environment. Disabling interrupt on a multiprocessor environment can be time consuming as the message is passed to all the processors. This message transmission lag, delays entry of threads into critical section and the system efficiency decreases.
  • 9. Mutex Locks As the synchronization hardware solution is not easy to implement for everyone A strict software approach called Mutex Locks was introduced. In this approach, in the entry section of code, a LOCK is acquired over the critical resources modified and used inside critical section, and in the exit section that LOCK is released. As the resource is locked while a process executes its critical section hence no other process can access it.
  • 10. Semaphores Introduction In 1965, Dijkstra proposed a new and very significant technique for managing concurrent processes by using the value of a simple integer variable to synchronize the progress of interacting processes. This integer variable is called semaphore. So it is basically a synchronizing tool and is accessed only through two low standard atomic operations, wait and signal designated by P(S) and V(S) respectively. In very simple words, semaphore is a variable which can hold only a non-negative Integer value, shared between all the threads, with operations wait and signal P(S): if S ≥ 1 then S := S - 1 else <block and enqueue the process>; V(S): if <some process is blocked on the queue> then <unblock a process> else S := S + 1;
  • 11. Semaphores The classical definitions of wait and signal are: • Wait: Decrements the value of its argument S, as soon as it would become non- negative(greater than or equal to 1). • Signal: Increments the value of its argument S, as there is no more process blocked on the queue.
  • 12. Semaphores Properties of Semaphores • It's simple and always have a non-negative Integer value. • Works with many processes. • Can have many different critical sections with different semaphores. • Each critical section has unique access semaphores. • Can permit multiple processes into the critical section at once, if desirable.
  • 13. Semaphores Types of Semaphores • Binary Semaphore: It is a special form of semaphore used for implementing mutual exclusion, hence it is often called a Mutex. A binary semaphore is initialized to 1 and only takes the values 0 and 1 during execution of a program. • Counting Semaphores: These are used to implement bounded concurrency.
  • 14. Semaphores Example of Use Shared var mutex: semaphore = 1; Process i begin . . P(mutex); execute CS; V(mutex); . . End;
  • 15. Semaphores Limitations of Semaphores • Priority Inversion is a big limitation of semaphores. • Their use is not enforced, but is by convention only. • With improper use, a process may block indefinitely. Such a situation is called Deadlock. We will be studying deadlocks in details in coming lessons.
  • 16. For Self Studies References • Abraham Silberschatz, Greg Gagne, and Peter Baer Galvin, "Operating System Concepts, Ninth Edition ", Chapter 5 • https://www.geeksforgeeks.org/process-synchronization-set-1/ • https://en.wikipedia.org/wiki/Synchronization_(computer_science)