SlideShare a Scribd company logo
Classical Problem Of
Synchronization
Submitted To: Namita mam
Submitted By:- Shakshi Kanwar Ranawat
Contents Of Discussion
 The Dining-Philosophers Problem
 The Reader Writers Problem
 The Bounded Buffer Problem
Dining-Philosophers Problem:
Rice
Dining-Philosophers Problem
• Table, a bowl of rice in center, five chairs, and five
chopsticks, also in each chair there is a philosopher.
• A philosopher may pick up only one chopstick at a
time.
• When a hungry philosopher has both her
chopsticks
at the same time, she eats without releasing her
chopsticks.
• When she is finished eating, she puts down both of
her chopsticks and starts thinking.
• From time to time, a philosopher gets hungry and
tries to pick up the two chopsticks that are closest
to her (chopsticks between her left and right
neighbors).
The Structure of philosopher i
do{
wait(chopstick[i]);
wait(chopstick[(i+1)%5]);
….
//eat
…..
signal(chopstick[i]);
signal(chopstick[(i+1)%5]);
…..
//think
…..
}while(TRUE);
Dining-Philosophers Problem (Cont.)
Solution:
 Present each chopstick by a semaphore.
 A philosopher tries to grab the chopstick by
executing a wait operation on that semaphore.
 She releases her chopsticks by executing the
signal operation on the appropriate semaphores.
This solution guarantees that no two neighbors are
eating simultaneously, but it could cause a
deadlock.
Suppose all five philosophers become hungry
simultaneously, and each grabs her left chopstick.
When each philosopher tries to grab her right
chopstick, she will cause the possibility that the
philosophers will starve to death.
Dining-Philosophers Problem (Cont.)
 We present a solution to the dining-philosophers
problem that ensure freedom from deadlock.
– Allow at most 4 philosophers to be sitting
simultaneously at the table.
– Allow a philosopher to pick up her chopstick only if
both chopsticks are available.
– An odd philosopher picks up first her left chopstick
and then her right chopstick, whereas, an even
philosopher picks up her right chopstick first and
then her left chopstick.
• Note: A deadlock-free solution does not necessarily
eliminate the possibility of starvation.
A semaphore solution:
// represent each chopstick with a semaphore
Semaphore chopstick[] = new Semaphore[5]; // all = 1 initially
process philosopher_i {
while (true) {
// pick up left chopstick
chopstick[i].acquire();
Cont…
// pick up right chopstick
chopstick[(i+1) % 5].acquire();
// eat
// put down left chopstick
chopstick[i].release();
// put down right chopstick
chopstick[(i+1) % 5].release();
// think
}
}
Cont…
This solution guarantees no two neighboring philosophers eat
simultaneously, but has the possibility of creating a deadlock
Uses of semaphores
 protecting acccess to a critical section (e.g., db in the R/W
problem)
 as a mutex lock (e.g., to protect the shared variables used in
solving a probem such as readerCount above)
 to protect a relationship (e.g., empty and full as used in the
P/C problem)
 to support atomicity (e.g., you pickup either both
chopsticks as the same time or neither, you cannot pickup
just one)
Application
 The dining philosophers problem
represents a situation that can occur in
large communities of processes that share
a sizeable pool of resources.
Bounded Buffer Problem
 also called the Producers and Consumers problem.
 A finite supply of containers is available. Producers
take an empty container and fill it with a product.
Consumers take a full container, consume the
product and leave an empty container.
 The main complexity of this problem is that we must
maintain the count for both the number of empty
and full containers that are available.
 Producers produce a product and consumers
consume the product, but both use of one of the
containers each time.
The Bounded Buffer Problem
Consider:
a buffer which can store n items
a producer process which creates the items (1 at a
time)
a consumer process which processes them (1 at a
time)
A producer cannot produce unless there is an
empty buffer slot to fill.
A consumer cannot consume unless there is at
least one produced item.
Cont..
Bounded-Buffer Problem Process
Shared data
semaphore full, empty, mutex;
Initialisation:
full = 0, empty = n, mutex = 1
Producer Process
do {
…
produce an item in nextp
…
wait(empty);
wait(mutex);…
add nextp to buffer…
signal(mutex);
signal(full);
} while (1);
Consumer Process
do {
wait(full)
wait(mutex);
…
remove an item from buffer to nextc
…
signal(mutex);
signal(empty);
…
consume the item in nextc
…
} while (1);
Application
A pipe or other finite queue (buffer), is an
example of the bounded buffer problem.
Reader Writer Problem
 If one notebook exists where writers may write
information to, only one writer may write at a time.
Confusion may arise if a reader is trying read at
the same as a writer is writing. Since readers only
look at the data, but do not modify the data, we
can allow more than one reader to read at the
same time.
 The main complexity with this problems stems from
allowing more than one reader to access the
data at the same time.
Reader Writer Problem
The Readers-Writers Problem
 A data item such as a file is shared among several
processes.
 Each process is classified as either a reader or
writer.
 Multiple readers may access the file
simultaneously.
 A writer must have exclusive access (i.e., cannot
share with either a reader or another writer).
 A solution gives priority to either readers or writers.
Cont….
 readers' priority: no reader is kept waiting unless a
writer has already obtained permission to access
the database
 writers' priority: if a writer is waiting to access the
database, no new readers can start reading
 A solution to either version may cause starvation
 in the readers' priority version, writers may starve
 in the writers' priority version, readers may starve
 A semaphore solution to the readers' priority
version (without addressing starvation):
Reader Writer Problem
Shared data
semaphore mutex, wrt;
Initially
mutex = 1, wrt = 1, readcount = 0
wait(wrt);
…
writing is performed
…
signal(wrt);
Readers-Writers Problem
Reader Process
wait(mutex);
readcount++;
if (readcount == 1)
wait(rt);
signal(mutex);
…
reading is performed
…
wait(mutex);
readcount--;
if (readcount == 0)
signal(wrt);
signal(mutex):
A semaphore solution to the
readers priority version :
Semaphore mutex = 1;
Semaphore db = 1;
int readerCount = 0;
Cont….
process writer {
db.acquire();
// write
db.release();
}
Conti…
process reader {
// protecting readerCount
mutex.acquire();
++readerCount;
if (readerCount == 1)
db.acquire();
mutex.release();
// read
// protecting readerCount
mutex.acquire();
--readerCount;
if (readerCount == 0)
db.release;
mutex.release();
}
readerCount is a <cs> over which we must maintain control and
we use mutex to do so.
Application
A message distribution system is an example
of Readers and Writers. We must keep track
of how many messages are in the queue
Thank You for listening

More Related Content

What's hot (20)

Deadlock
DeadlockDeadlock
Deadlock
Rajandeep Gill
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
hodcsencet
 
Multi processor scheduling
Multi  processor schedulingMulti  processor scheduling
Multi processor scheduling
Shashank Kapoor
 
SCHEDULING ALGORITHMS
SCHEDULING ALGORITHMSSCHEDULING ALGORITHMS
SCHEDULING ALGORITHMS
Dhaval Sakhiya
 
OS - Process Concepts
OS - Process ConceptsOS - Process Concepts
OS - Process Concepts
Mukesh Chinta
 
Graph coloring using backtracking
Graph coloring using backtrackingGraph coloring using backtracking
Graph coloring using backtracking
shashidharPapishetty
 
Demand paging
Demand pagingDemand paging
Demand paging
Trinity Dwarka
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
Nikhil Sharma
 
Bankers algorithm
Bankers algorithmBankers algorithm
Bankers algorithm
AAQIB PARREY
 
Single source Shortest path algorithm with example
Single source Shortest path algorithm with exampleSingle source Shortest path algorithm with example
Single source Shortest path algorithm with example
VINITACHAUHAN21
 
Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating system
Sara Ali
 
Sum of subsets problem by backtracking 
Sum of subsets problem by backtracking Sum of subsets problem by backtracking 
Sum of subsets problem by backtracking 
Hasanain Alshadoodee
 
Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)
swapnac12
 
Daa unit 1
Daa unit 1Daa unit 1
Daa unit 1
Abhimanyu Mishra
 
Semaphores
SemaphoresSemaphores
Semaphores
Mohd Arif
 
Chapter 8 - Main Memory
Chapter 8 - Main MemoryChapter 8 - Main Memory
Chapter 8 - Main Memory
Wayne Jones Jnr
 
Computer architecture pipelining
Computer architecture pipeliningComputer architecture pipelining
Computer architecture pipelining
Mazin Alwaaly
 
Multithreading computer architecture
 Multithreading computer architecture  Multithreading computer architecture
Multithreading computer architecture
Haris456
 
Semaphore
Semaphore Semaphore
Semaphore
LakshmiSamivel
 
Process synchronization
Process synchronizationProcess synchronization
Process synchronization
Syed Hassan Ali
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
hodcsencet
 
Multi processor scheduling
Multi  processor schedulingMulti  processor scheduling
Multi processor scheduling
Shashank Kapoor
 
OS - Process Concepts
OS - Process ConceptsOS - Process Concepts
OS - Process Concepts
Mukesh Chinta
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
Nikhil Sharma
 
Single source Shortest path algorithm with example
Single source Shortest path algorithm with exampleSingle source Shortest path algorithm with example
Single source Shortest path algorithm with example
VINITACHAUHAN21
 
Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating system
Sara Ali
 
Sum of subsets problem by backtracking 
Sum of subsets problem by backtracking Sum of subsets problem by backtracking 
Sum of subsets problem by backtracking 
Hasanain Alshadoodee
 
Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)
swapnac12
 
Computer architecture pipelining
Computer architecture pipeliningComputer architecture pipelining
Computer architecture pipelining
Mazin Alwaaly
 
Multithreading computer architecture
 Multithreading computer architecture  Multithreading computer architecture
Multithreading computer architecture
Haris456
 

Viewers also liked (15)

software project management Waterfall model
software project management Waterfall modelsoftware project management Waterfall model
software project management Waterfall model
REHMAT ULLAH
 
Bluetooth - Overview
Bluetooth - OverviewBluetooth - Overview
Bluetooth - Overview
Shobana Pattabiraman
 
Visibility control in java
Visibility control in javaVisibility control in java
Visibility control in java
Tech_MX
 
Bluetooth wi fi wi max 2, 3
Bluetooth wi fi wi max 2, 3Bluetooth wi fi wi max 2, 3
Bluetooth wi fi wi max 2, 3
jandrewsxu
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in java
Google
 
Access modifiers in java
Access modifiers in javaAccess modifiers in java
Access modifiers in java
Muthukumaran Subramanian
 
Bluetooth
BluetoothBluetooth
Bluetooth
Sumeet Rayat
 
Bluetooth technology
Bluetooth technologyBluetooth technology
Bluetooth technology
Rohit Roy
 
Awt
AwtAwt
Awt
Rakesh Patil
 
Wi-Fi vs Bluetooth
Wi-Fi vs BluetoothWi-Fi vs Bluetooth
Wi-Fi vs Bluetooth
Arun ACE
 
Waterfall Model
Waterfall ModelWaterfall Model
Waterfall Model
university of education,Lahore
 
Java access modifiers
Java access modifiersJava access modifiers
Java access modifiers
Srinivas Reddy
 
Waterfall model ppt final
Waterfall model ppt  finalWaterfall model ppt  final
Waterfall model ppt final
shiva krishna
 
Waterfall model
Waterfall modelWaterfall model
Waterfall model
BHARGAV VISANI
 
Wi-Fi Technology
Wi-Fi TechnologyWi-Fi Technology
Wi-Fi Technology
Naveen Kumar
 

Similar to Classical problem of synchronization (20)

Classical-Problem-of-Synchronization in OS
Classical-Problem-of-Synchronization in OSClassical-Problem-of-Synchronization in OS
Classical-Problem-of-Synchronization in OS
VivekanandaGN1
 
Operating system 25 classical problems of synchronization
Operating system 25 classical problems of synchronizationOperating system 25 classical problems of synchronization
Operating system 25 classical problems of synchronization
Vaibhav Khanna
 
Deadlock _Classic problems.pptx
Deadlock _Classic problems.pptxDeadlock _Classic problems.pptx
Deadlock _Classic problems.pptx
GopikaS12
 
UNIT III Process Synchronization.docx
UNIT III Process Synchronization.docxUNIT III Process Synchronization.docx
UNIT III Process Synchronization.docx
karthikaparthasarath
 
Dining Philosopher Problem
Dining Philosopher ProblemDining Philosopher Problem
Dining Philosopher Problem
Raval Vijay
 
Dining Philosopher's Problem
Dining Philosopher's ProblemDining Philosopher's Problem
Dining Philosopher's Problem
Yash Mittal
 
Dining Philosopher Problem and Solution
Dining Philosopher Problem and SolutionDining Philosopher Problem and Solution
Dining Philosopher Problem and Solution
Lahiru Danushka
 
12 deadlock concept
12 deadlock concept12 deadlock concept
12 deadlock concept
DeepaMaria10489
 
Classical problems of process synchronization
Classical problems of process synchronizationClassical problems of process synchronization
Classical problems of process synchronization
sangrampatil81
 
Zuhri ramadhan dining philosophers theory and concept in operating system
Zuhri ramadhan   dining philosophers theory and concept in operating systemZuhri ramadhan   dining philosophers theory and concept in operating system
Zuhri ramadhan dining philosophers theory and concept in operating system
Raj Kamal
 
Dinning philosopher problem cs 603 format.ppt
Dinning philosopher problem cs 603 format.pptDinning philosopher problem cs 603 format.ppt
Dinning philosopher problem cs 603 format.ppt
22ad0301
 
Synchronization problems
Synchronization problemsSynchronization problems
Synchronization problems
V.V.Vanniaperumal College for Women
 
DPP
DPPDPP
DPP
Ramasubbu .P
 
Dining philosopher
Dining philosopherDining philosopher
Dining philosopher
.AIR UNIVERSITY ISLAMABAD
 
Dining philosopher problem operating system
Dining philosopher problem operating system Dining philosopher problem operating system
Dining philosopher problem operating system
anushkashastri
 
Deadlock.ppt
Deadlock.pptDeadlock.ppt
Deadlock.ppt
AhmedKhairulAmin
 
Operating systems
Operating systemsOperating systems
Operating systems
Abraham
 
Operating systems
Operating systemsOperating systems
Operating systems
Abraham
 
Data raceData raceData raceData race.pptx
Data raceData raceData raceData race.pptxData raceData raceData raceData race.pptx
Data raceData raceData raceData race.pptx
Balasubramanian699229
 
Concurrent Programming Patterns
Concurrent Programming PatternsConcurrent Programming Patterns
Concurrent Programming Patterns
Dilum Bandara
 
Classical-Problem-of-Synchronization in OS
Classical-Problem-of-Synchronization in OSClassical-Problem-of-Synchronization in OS
Classical-Problem-of-Synchronization in OS
VivekanandaGN1
 
Operating system 25 classical problems of synchronization
Operating system 25 classical problems of synchronizationOperating system 25 classical problems of synchronization
Operating system 25 classical problems of synchronization
Vaibhav Khanna
 
Deadlock _Classic problems.pptx
Deadlock _Classic problems.pptxDeadlock _Classic problems.pptx
Deadlock _Classic problems.pptx
GopikaS12
 
UNIT III Process Synchronization.docx
UNIT III Process Synchronization.docxUNIT III Process Synchronization.docx
UNIT III Process Synchronization.docx
karthikaparthasarath
 
Dining Philosopher Problem
Dining Philosopher ProblemDining Philosopher Problem
Dining Philosopher Problem
Raval Vijay
 
Dining Philosopher's Problem
Dining Philosopher's ProblemDining Philosopher's Problem
Dining Philosopher's Problem
Yash Mittal
 
Dining Philosopher Problem and Solution
Dining Philosopher Problem and SolutionDining Philosopher Problem and Solution
Dining Philosopher Problem and Solution
Lahiru Danushka
 
Classical problems of process synchronization
Classical problems of process synchronizationClassical problems of process synchronization
Classical problems of process synchronization
sangrampatil81
 
Zuhri ramadhan dining philosophers theory and concept in operating system
Zuhri ramadhan   dining philosophers theory and concept in operating systemZuhri ramadhan   dining philosophers theory and concept in operating system
Zuhri ramadhan dining philosophers theory and concept in operating system
Raj Kamal
 
Dinning philosopher problem cs 603 format.ppt
Dinning philosopher problem cs 603 format.pptDinning philosopher problem cs 603 format.ppt
Dinning philosopher problem cs 603 format.ppt
22ad0301
 
Dining philosopher problem operating system
Dining philosopher problem operating system Dining philosopher problem operating system
Dining philosopher problem operating system
anushkashastri
 
Operating systems
Operating systemsOperating systems
Operating systems
Abraham
 
Operating systems
Operating systemsOperating systems
Operating systems
Abraham
 
Data raceData raceData raceData race.pptx
Data raceData raceData raceData race.pptxData raceData raceData raceData race.pptx
Data raceData raceData raceData race.pptx
Balasubramanian699229
 
Concurrent Programming Patterns
Concurrent Programming PatternsConcurrent Programming Patterns
Concurrent Programming Patterns
Dilum Bandara
 

Recently uploaded (20)

How to Configure Flexible Working Schedule in Odoo 18 Employee
How to Configure Flexible Working Schedule in Odoo 18 EmployeeHow to Configure Flexible Working Schedule in Odoo 18 Employee
How to Configure Flexible Working Schedule in Odoo 18 Employee
Celine George
 
How to Setup WhatsApp in Odoo 17 - Odoo Slides
How to Setup WhatsApp in Odoo 17 - Odoo SlidesHow to Setup WhatsApp in Odoo 17 - Odoo Slides
How to Setup WhatsApp in Odoo 17 - Odoo Slides
Celine George
 
N.C. DPI's 2023 Language Diversity Briefing
N.C. DPI's 2023 Language Diversity BriefingN.C. DPI's 2023 Language Diversity Briefing
N.C. DPI's 2023 Language Diversity Briefing
Mebane Rash
 
TLE 7 - 2nd Topic - Codes and Standards in Industrial Arts Services.pptx
TLE 7 - 2nd Topic - Codes and Standards in Industrial Arts Services.pptxTLE 7 - 2nd Topic - Codes and Standards in Industrial Arts Services.pptx
TLE 7 - 2nd Topic - Codes and Standards in Industrial Arts Services.pptx
RizaBedayo
 
How to Configure Restaurants in Odoo 17 Point of Sale
How to Configure Restaurants in Odoo 17 Point of SaleHow to Configure Restaurants in Odoo 17 Point of Sale
How to Configure Restaurants in Odoo 17 Point of Sale
Celine George
 
Principle and Practices of Animal Breeding || Boby Basnet
Principle and Practices of Animal Breeding || Boby BasnetPrinciple and Practices of Animal Breeding || Boby Basnet
Principle and Practices of Animal Breeding || Boby Basnet
Boby Basnet
 
Database population in Odoo 18 - Odoo slides
Database population in Odoo 18 - Odoo slidesDatabase population in Odoo 18 - Odoo slides
Database population in Odoo 18 - Odoo slides
Celine George
 
Modeling-Simple-Equation-Using-Bar-Models.pptx
Modeling-Simple-Equation-Using-Bar-Models.pptxModeling-Simple-Equation-Using-Bar-Models.pptx
Modeling-Simple-Equation-Using-Bar-Models.pptx
maribethlacno2
 
English 4 Quarter 4 Week 4 Classroom Obs
English 4 Quarter 4 Week 4 Classroom ObsEnglish 4 Quarter 4 Week 4 Classroom Obs
English 4 Quarter 4 Week 4 Classroom Obs
NerissaMendez1
 
POWERPOINT-PRESENTATION_DM-NO.017-S.2025.pptx
POWERPOINT-PRESENTATION_DM-NO.017-S.2025.pptxPOWERPOINT-PRESENTATION_DM-NO.017-S.2025.pptx
POWERPOINT-PRESENTATION_DM-NO.017-S.2025.pptx
MarilenQuintoSimbula
 
Fuel part 1.pptx........................
Fuel part 1.pptx........................Fuel part 1.pptx........................
Fuel part 1.pptx........................
ksbhattadcm
 
Year 10 The Senior Phase Session 3 Term 1.pptx
Year 10 The Senior Phase Session 3 Term 1.pptxYear 10 The Senior Phase Session 3 Term 1.pptx
Year 10 The Senior Phase Session 3 Term 1.pptx
mansk2
 
Computer Application in Business (commerce)
Computer Application in Business (commerce)Computer Application in Business (commerce)
Computer Application in Business (commerce)
Sudar Sudar
 
TRANSFER OF PATIENTS IN HOSPITAL SETTING.pptx
TRANSFER OF PATIENTS IN HOSPITAL SETTING.pptxTRANSFER OF PATIENTS IN HOSPITAL SETTING.pptx
TRANSFER OF PATIENTS IN HOSPITAL SETTING.pptx
PoojaSen20
 
Adventure Activities Final By H R Gohil Sir
Adventure Activities Final By H R Gohil SirAdventure Activities Final By H R Gohil Sir
Adventure Activities Final By H R Gohil Sir
GUJARATCOMMERCECOLLE
 
The Broccoli Dog's inner voice (look A)
The Broccoli Dog's inner voice  (look A)The Broccoli Dog's inner voice  (look A)
The Broccoli Dog's inner voice (look A)
merasan
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
FESTIVAL: SINULOG & THINGYAN-LESSON 4.pptx
FESTIVAL: SINULOG & THINGYAN-LESSON 4.pptxFESTIVAL: SINULOG & THINGYAN-LESSON 4.pptx
FESTIVAL: SINULOG & THINGYAN-LESSON 4.pptx
DanmarieMuli1
 
Essentials of a Good PMO, presented by Aalok Sonawala
Essentials of a Good PMO, presented by Aalok SonawalaEssentials of a Good PMO, presented by Aalok Sonawala
Essentials of a Good PMO, presented by Aalok Sonawala
Association for Project Management
 
APM People Interest Network Conference - Tim Lyons - The neurological levels ...
APM People Interest Network Conference - Tim Lyons - The neurological levels ...APM People Interest Network Conference - Tim Lyons - The neurological levels ...
APM People Interest Network Conference - Tim Lyons - The neurological levels ...
Association for Project Management
 
How to Configure Flexible Working Schedule in Odoo 18 Employee
How to Configure Flexible Working Schedule in Odoo 18 EmployeeHow to Configure Flexible Working Schedule in Odoo 18 Employee
How to Configure Flexible Working Schedule in Odoo 18 Employee
Celine George
 
How to Setup WhatsApp in Odoo 17 - Odoo Slides
How to Setup WhatsApp in Odoo 17 - Odoo SlidesHow to Setup WhatsApp in Odoo 17 - Odoo Slides
How to Setup WhatsApp in Odoo 17 - Odoo Slides
Celine George
 
N.C. DPI's 2023 Language Diversity Briefing
N.C. DPI's 2023 Language Diversity BriefingN.C. DPI's 2023 Language Diversity Briefing
N.C. DPI's 2023 Language Diversity Briefing
Mebane Rash
 
TLE 7 - 2nd Topic - Codes and Standards in Industrial Arts Services.pptx
TLE 7 - 2nd Topic - Codes and Standards in Industrial Arts Services.pptxTLE 7 - 2nd Topic - Codes and Standards in Industrial Arts Services.pptx
TLE 7 - 2nd Topic - Codes and Standards in Industrial Arts Services.pptx
RizaBedayo
 
How to Configure Restaurants in Odoo 17 Point of Sale
How to Configure Restaurants in Odoo 17 Point of SaleHow to Configure Restaurants in Odoo 17 Point of Sale
How to Configure Restaurants in Odoo 17 Point of Sale
Celine George
 
Principle and Practices of Animal Breeding || Boby Basnet
Principle and Practices of Animal Breeding || Boby BasnetPrinciple and Practices of Animal Breeding || Boby Basnet
Principle and Practices of Animal Breeding || Boby Basnet
Boby Basnet
 
Database population in Odoo 18 - Odoo slides
Database population in Odoo 18 - Odoo slidesDatabase population in Odoo 18 - Odoo slides
Database population in Odoo 18 - Odoo slides
Celine George
 
Modeling-Simple-Equation-Using-Bar-Models.pptx
Modeling-Simple-Equation-Using-Bar-Models.pptxModeling-Simple-Equation-Using-Bar-Models.pptx
Modeling-Simple-Equation-Using-Bar-Models.pptx
maribethlacno2
 
English 4 Quarter 4 Week 4 Classroom Obs
English 4 Quarter 4 Week 4 Classroom ObsEnglish 4 Quarter 4 Week 4 Classroom Obs
English 4 Quarter 4 Week 4 Classroom Obs
NerissaMendez1
 
POWERPOINT-PRESENTATION_DM-NO.017-S.2025.pptx
POWERPOINT-PRESENTATION_DM-NO.017-S.2025.pptxPOWERPOINT-PRESENTATION_DM-NO.017-S.2025.pptx
POWERPOINT-PRESENTATION_DM-NO.017-S.2025.pptx
MarilenQuintoSimbula
 
Fuel part 1.pptx........................
Fuel part 1.pptx........................Fuel part 1.pptx........................
Fuel part 1.pptx........................
ksbhattadcm
 
Year 10 The Senior Phase Session 3 Term 1.pptx
Year 10 The Senior Phase Session 3 Term 1.pptxYear 10 The Senior Phase Session 3 Term 1.pptx
Year 10 The Senior Phase Session 3 Term 1.pptx
mansk2
 
Computer Application in Business (commerce)
Computer Application in Business (commerce)Computer Application in Business (commerce)
Computer Application in Business (commerce)
Sudar Sudar
 
TRANSFER OF PATIENTS IN HOSPITAL SETTING.pptx
TRANSFER OF PATIENTS IN HOSPITAL SETTING.pptxTRANSFER OF PATIENTS IN HOSPITAL SETTING.pptx
TRANSFER OF PATIENTS IN HOSPITAL SETTING.pptx
PoojaSen20
 
Adventure Activities Final By H R Gohil Sir
Adventure Activities Final By H R Gohil SirAdventure Activities Final By H R Gohil Sir
Adventure Activities Final By H R Gohil Sir
GUJARATCOMMERCECOLLE
 
The Broccoli Dog's inner voice (look A)
The Broccoli Dog's inner voice  (look A)The Broccoli Dog's inner voice  (look A)
The Broccoli Dog's inner voice (look A)
merasan
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
FESTIVAL: SINULOG & THINGYAN-LESSON 4.pptx
FESTIVAL: SINULOG & THINGYAN-LESSON 4.pptxFESTIVAL: SINULOG & THINGYAN-LESSON 4.pptx
FESTIVAL: SINULOG & THINGYAN-LESSON 4.pptx
DanmarieMuli1
 
APM People Interest Network Conference - Tim Lyons - The neurological levels ...
APM People Interest Network Conference - Tim Lyons - The neurological levels ...APM People Interest Network Conference - Tim Lyons - The neurological levels ...
APM People Interest Network Conference - Tim Lyons - The neurological levels ...
Association for Project Management
 

Classical problem of synchronization

  • 1. Classical Problem Of Synchronization Submitted To: Namita mam Submitted By:- Shakshi Kanwar Ranawat
  • 2. Contents Of Discussion  The Dining-Philosophers Problem  The Reader Writers Problem  The Bounded Buffer Problem
  • 4. Dining-Philosophers Problem • Table, a bowl of rice in center, five chairs, and five chopsticks, also in each chair there is a philosopher. • A philosopher may pick up only one chopstick at a time. • When a hungry philosopher has both her chopsticks at the same time, she eats without releasing her chopsticks. • When she is finished eating, she puts down both of her chopsticks and starts thinking. • From time to time, a philosopher gets hungry and tries to pick up the two chopsticks that are closest to her (chopsticks between her left and right neighbors).
  • 5. The Structure of philosopher i do{ wait(chopstick[i]); wait(chopstick[(i+1)%5]); …. //eat ….. signal(chopstick[i]); signal(chopstick[(i+1)%5]); ….. //think ….. }while(TRUE);
  • 6. Dining-Philosophers Problem (Cont.) Solution:  Present each chopstick by a semaphore.  A philosopher tries to grab the chopstick by executing a wait operation on that semaphore.  She releases her chopsticks by executing the signal operation on the appropriate semaphores. This solution guarantees that no two neighbors are eating simultaneously, but it could cause a deadlock. Suppose all five philosophers become hungry simultaneously, and each grabs her left chopstick. When each philosopher tries to grab her right chopstick, she will cause the possibility that the philosophers will starve to death.
  • 7. Dining-Philosophers Problem (Cont.)  We present a solution to the dining-philosophers problem that ensure freedom from deadlock. – Allow at most 4 philosophers to be sitting simultaneously at the table. – Allow a philosopher to pick up her chopstick only if both chopsticks are available. – An odd philosopher picks up first her left chopstick and then her right chopstick, whereas, an even philosopher picks up her right chopstick first and then her left chopstick. • Note: A deadlock-free solution does not necessarily eliminate the possibility of starvation.
  • 8. A semaphore solution: // represent each chopstick with a semaphore Semaphore chopstick[] = new Semaphore[5]; // all = 1 initially process philosopher_i { while (true) { // pick up left chopstick chopstick[i].acquire();
  • 9. Cont… // pick up right chopstick chopstick[(i+1) % 5].acquire(); // eat // put down left chopstick chopstick[i].release(); // put down right chopstick chopstick[(i+1) % 5].release(); // think } }
  • 10. Cont… This solution guarantees no two neighboring philosophers eat simultaneously, but has the possibility of creating a deadlock
  • 11. Uses of semaphores  protecting acccess to a critical section (e.g., db in the R/W problem)  as a mutex lock (e.g., to protect the shared variables used in solving a probem such as readerCount above)  to protect a relationship (e.g., empty and full as used in the P/C problem)  to support atomicity (e.g., you pickup either both chopsticks as the same time or neither, you cannot pickup just one)
  • 12. Application  The dining philosophers problem represents a situation that can occur in large communities of processes that share a sizeable pool of resources.
  • 13. Bounded Buffer Problem  also called the Producers and Consumers problem.  A finite supply of containers is available. Producers take an empty container and fill it with a product. Consumers take a full container, consume the product and leave an empty container.  The main complexity of this problem is that we must maintain the count for both the number of empty and full containers that are available.  Producers produce a product and consumers consume the product, but both use of one of the containers each time.
  • 14. The Bounded Buffer Problem Consider: a buffer which can store n items a producer process which creates the items (1 at a time) a consumer process which processes them (1 at a time) A producer cannot produce unless there is an empty buffer slot to fill. A consumer cannot consume unless there is at least one produced item.
  • 16. Bounded-Buffer Problem Process Shared data semaphore full, empty, mutex; Initialisation: full = 0, empty = n, mutex = 1
  • 17. Producer Process do { … produce an item in nextp … wait(empty); wait(mutex);… add nextp to buffer… signal(mutex); signal(full); } while (1);
  • 18. Consumer Process do { wait(full) wait(mutex); … remove an item from buffer to nextc … signal(mutex); signal(empty); … consume the item in nextc … } while (1);
  • 19. Application A pipe or other finite queue (buffer), is an example of the bounded buffer problem.
  • 20. Reader Writer Problem  If one notebook exists where writers may write information to, only one writer may write at a time. Confusion may arise if a reader is trying read at the same as a writer is writing. Since readers only look at the data, but do not modify the data, we can allow more than one reader to read at the same time.  The main complexity with this problems stems from allowing more than one reader to access the data at the same time.
  • 22. The Readers-Writers Problem  A data item such as a file is shared among several processes.  Each process is classified as either a reader or writer.  Multiple readers may access the file simultaneously.  A writer must have exclusive access (i.e., cannot share with either a reader or another writer).  A solution gives priority to either readers or writers.
  • 23. Cont….  readers' priority: no reader is kept waiting unless a writer has already obtained permission to access the database  writers' priority: if a writer is waiting to access the database, no new readers can start reading  A solution to either version may cause starvation  in the readers' priority version, writers may starve  in the writers' priority version, readers may starve  A semaphore solution to the readers' priority version (without addressing starvation):
  • 24. Reader Writer Problem Shared data semaphore mutex, wrt; Initially mutex = 1, wrt = 1, readcount = 0 wait(wrt); … writing is performed … signal(wrt);
  • 25. Readers-Writers Problem Reader Process wait(mutex); readcount++; if (readcount == 1) wait(rt); signal(mutex); … reading is performed … wait(mutex); readcount--; if (readcount == 0) signal(wrt); signal(mutex):
  • 26. A semaphore solution to the readers priority version : Semaphore mutex = 1; Semaphore db = 1; int readerCount = 0;
  • 28. Conti… process reader { // protecting readerCount mutex.acquire(); ++readerCount; if (readerCount == 1) db.acquire(); mutex.release(); // read // protecting readerCount mutex.acquire(); --readerCount; if (readerCount == 0) db.release; mutex.release(); } readerCount is a <cs> over which we must maintain control and we use mutex to do so.
  • 29. Application A message distribution system is an example of Readers and Writers. We must keep track of how many messages are in the queue
  • 30. Thank You for listening