[go: up one dir, main page]

0% found this document useful (0 votes)
105 views3 pages

Dining Philosopher Problem - Os Proposal

The document proposes a project to solve the dining philosophers problem using mutex locks and pthreads. The dining philosophers problem involves 5 philosophers who take turns thinking and eating with shared chopsticks. The project will implement this using mutex locks to prevent philosophers from interrupting each other when changing states, and pthreads to manage the threads representing each philosopher. The methodology will use an approach where odd numbered philosophers pick up the right chopstick first, and even numbered philosophers pick up the left chopstick first, to avoid deadlocks.

Uploaded by

Mehak Aftab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
105 views3 pages

Dining Philosopher Problem - Os Proposal

The document proposes a project to solve the dining philosophers problem using mutex locks and pthreads. The dining philosophers problem involves 5 philosophers who take turns thinking and eating with shared chopsticks. The project will implement this using mutex locks to prevent philosophers from interrupting each other when changing states, and pthreads to manage the threads representing each philosopher. The methodology will use an approach where odd numbered philosophers pick up the right chopstick first, and even numbered philosophers pick up the left chopstick first, to avoid deadlocks.

Uploaded by

Mehak Aftab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

OPERATING SYSTEM

DINING PHILOSOPHERS PROBLEM


Project Proposal

Submitted To:
SIR USMAN AHMED RAZA
Submitted By:
1. SANA RAFIQUE (2019-CS-687)
2. MAYSOON SHAHID (2019-CS-673)
Department of Computer Science
University of Engineering and Technology (New
Campus), Lahore
DINING PHILOSOPHERS PROBLEM
Objective:
The main objective of this project is to solve the Dining Philosopher Problem using
the concepts of Mutex Lock and pthread library.
Introduction:
The dining philosophers problem is a very famous and interesting problem used to
demonstrate the concept of deadlock. 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.
Here, we are going to implement this problem using the concepts of Threads and
mutex lock.
MUTEX:
A Mutex is a lock that we set before using a shared resource and release after
using it. There are a couple of mechanisms that implement locks. Mutex (mutual
exclusion) is the fundamental synchronization technique. The idea is simple:
whenever a work unit accesses the critical section, it first needs a lock that
guarantees no one else at this time is accessing the critical section. When the work
unit exits the critical section, it returns the lock for other work units to access.

In the dining philosopher problem, we can implement an algorithm with mutexes


that guarantee the philosophers not to be interrupted when they are changing their
states (e.g. the process of picking up chopsticks).

PThread:
PThread library provides programmer with API for creating and managing
threads. API specifies behavior of the thread library, implementation is up to
development of the library.
Problem Description:-
Consider five philosophers (numbered 0 to 4) who spend their lives thinking and
eating. The philosophers share a circular table surrounded by five chairs, each
belonging to one philosopher. In the center of the table is a bowl of rice, and the
table is laid with five single chopsticks. When a philosopher thinks (for a random
amount of time between 1 and 3 seconds), she does not interact with her
colleagues. From time to time, a philosopher gets hungry and tries to pick up the
two chopsticks that are closest to her (the chopsticks that are between her and her
left and right neighbors). A philosopher may pick up only one chopstick at a time.
Obviously, she cannot pick up a chopstick that is already in the hand of a neighbor.
When a hungry philosopher has both her chopsticks at the same time, she eats (for
a random amount of time between 1 and 3 seconds) without releasing the
chopsticks. When she is finished eating, she puts down both chopsticks and starts
thinking again. A deadlock condition in the simulation dining philosophers
problem occurs when at one time; all the philosophers get hungry simultaneously,
and all philosophers take the chopsticks in his left hand. By the time the
philosopher will take the chopsticks in the right hand, then there was a deadlock
condition since all philosophers will both waiting for chopsticks on the right.

Methodology:-
There are several solutions which are:-
1. Allows at most four philosophers who sit together at one table.
2. Allows a philosopher take chopsticks only if both chopsticks were there
3. Allow only Odd numbered philosophers pick up the right chopstick first and
then the left, while even numbered philosophers pick up the left chopstick
first and then the right.
The first and second solution is not appropriate that’s why we use third solution in
our project to solve dining philosophers problem.

You might also like