## Synchronization-Problems

Edit

### Subtopic

Edit

Question :- Write short note on

1. Dining Philosopher problem
2. Produced Consumer Problem
3. Reader  Writer  Problem          ( 6 m )  (  May – June 18 )

### Dining Philosopher Problem

Edit

The dining philosopher problem can be stated as follows :

Five philosophers are seated around a round table. Each philosopher  has a plate of spaghetti. Each there is a fork between every pair of adjacent plates. A philosopher needs two forks to eat spaghetti. Each philosopher alternately eats and thinks. When a philosopher gets hungry, he tries to acquire his left and right fork, one at a time, in either order. If a philosopher acquires two forks successfully, he eats for a file, then puts down the forks and continues to think.

Figure :- Dining arrangement for  philosophers.  Deadlock will arise if each philosopher picks up one fork each and waits for another fork.  Deadlock can be avoided by allowing only four philosophers, in the dining room. With four philosophers, at least one philosopher will have access to two forks.

### The producer Consumer Problem

Edit

Producer consumer problem is example classic problems of synchronization. Producer process produce data item that consumer process consumes later. Buffer is used between producer and consumer. Buffer creates problems of sharing. The producer- consumer problems shows the need for synchronization in systems where many processes share a resource. In the problem, two processes share a fixed size buffer. One process produces data items and deposits it in the buffer  while the other process consumes data items from the buffer.

The producer cannot deposit its data if the buffer is full similarly, a consumer cannot retrieve any data if the buffer is empty. If the buffer is not full, a producer can deposit its data. The consumer should be allowed to retrieve a data item if buffer contains . Buffer  is having two main problems:-

1. Full Buffer                           b) Empty buffer

A solution to the producer – consumer problem satisfy the following conditions :-

1) When buffer is full, producer must wait. Producer do not produce data item

2) When buffer is empty, consumer must wait.

3) Mutual exclusion is required for accessing the buffer.

Producer-consumer problem is solved by using semaphore, mutex and monitor

### Reader –Writer Problem

Edit

When two types of processes need to access a shared resource such as a file or database. They called these processes reader and writers are those who want train schedule information. They are called reader  because readers do not change the content of the database. Many readers may access the database at once. There is no need to enforce mutual exclusion among readers. The writers are those who making reservations on a particular train. Writer can modify the database, so it must have exclusive access. When writer is active, no other readers on writers may be active. Therefore , it must enforce mutual exclusion if there are groups of readers and a writer.

Reader writer problem is similar to one which a file is to be shared among a set of processes. If a process want only to other process that also wants to read the file. If the writer wants to append the file, then no other process should have access to the file when the writer has access to it.

If reader having higher priority than the writer, then there will be starvation with writers. For writer having higher priority than reader then starvation with readers.

Reader-writer problem can be solved by same way as producer – consumer problem by using semaphore, mutex.

## References

Edit
• WikiNote Foundation

Last modified: Friday, 20 September 2019, 10:25 AM