0% found this document useful (0 votes)
8 views9 pages

Process Synchronization - Classical Problems of Synchronization

The document discusses classical problems of synchronization in computing, specifically the Producer-Consumer Problem, the Readers-Writers Problem, and the Dining Philosophers Problem. It outlines the challenges and solutions using semaphores for each problem, emphasizing the need for mutual exclusion and the management of shared resources. The document also notes that while certain solutions guarantee mutual exclusion, they may not ensure progress.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views9 pages

Process Synchronization - Classical Problems of Synchronization

The document discusses classical problems of synchronization in computing, specifically the Producer-Consumer Problem, the Readers-Writers Problem, and the Dining Philosophers Problem. It outlines the challenges and solutions using semaphores for each problem, emphasizing the need for mutual exclusion and the management of shared resources. The document also notes that while certain solutions guarantee mutual exclusion, they may not ensure progress.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Process Synchronization - Classical

Problems of Synchronization
Lecture - 11
Producer - Consumer Problem / The Bounded-Buffer Problem

• Problem Statement –
• We have a buffer of fixed size.
• A producer can produce an item and can place in the buffer.
• A consumer can pick items and can consume them.
• We need to ensure that when a producer is placing an item in
the buffer, then at the same time consumer should not
consume any item.
• In this problem, buffer is the critical section.
Cont..

Solution using semaphores:

Three semaphores are used here:


Semaphore S = 1, this semaphore is used to handle CS
Semaphore E = n, where E stands for empty slots. Initially, all the slots are
empty, so E is initialized by n (where n is the total size of the buffer)
Semaphore F = 0, It will check how many slots are full.
The Readers-Writers Problem:
• There is a shared resource which should be accessed by multiple processes.
• There are two types of processes in this context. They
are reader and writer.
• Any number of readers can read from the shared resource simultaneously,
but only one writer can write to the shared resource.
• When readers are reading, then no writers are allowed to write.
• When a writer is writing data to the resource, no other process can access
the resource.
Cont..

Solution using semaphores:


Semaphores wrt and mutex are assigned an initial value of 1
THE DINING PHILOSOPHERS PROBLEM

• The dining philosopher's problem is the classical problem of


synchronization which says that five philosophers are sitting
around a circular table and their job is to think and eat
alternatively.
• A bowl of noodles is placed at the center of the table along
with five chopsticks for each of the philosophers.
• To eat a philosopher needs both their right and a left
chopstick. A philosopher can only eat if both immediate left
and right chopsticks of the philosopher are available.
• In case if both immediate left and right chopsticks of the
philosopher are not available then the philosopher puts down
their (either left or right) chopstick and starts thinking again.
• The five Philosophers are represented as P0, P1, P2, P3, and
P4 and five chopsticks by C0, C1, C2, C3, and C4.
Cont..
Cont..

This solution guarantees ME but not Progress. To ensure progress I


have changed the solution in the next slide.
Cont..

You might also like