Void Philosopher(Void)
{
While(true)
{
Thinking(),
Take-spoon(i),
Take-spoon((i+1)%N),
EAT(),
Put-spoon(i),
Put spoon((i+1)%N),
}
}
p1
p2
p0
p3
p4
code that must be followed by philosopers
f0
f1
f2
f3
f4
Changes in function of code while accesing
food by philosophers…..
• Void Philosopher(Void)
• {
• While(true)
• {
• Thinking(),
• Wait(Take-spoon(i)),
• Wait(Take-spoon((i+1)%N)),
• EAT(),
• Signal(Put-spoon(i)),
• Signal(Put spoon((i+1)%N)),
• }
• }
Here to solve dp problem ,we will use N no of
Binary Semaphores..
• S[i]
• N=no of spoons
• So here we will use 5 semaphores
• all the semaphores are initialized with 1
•S0 , S1 , S2 , S3 , S4
1 1 1 1 1
Philosopher need what semaphore as value 1
at which time?
philosopher 1st clock cycle semaphore 2nd clock cycle semaphore
p0 s0 s1
p1 s1 s2
p2 s2 s3
p3 s3 s4
p4 s4 s0
Exception of MUTUAL EXCLUSION
MUTUAL EXCLUSION-
there can be only one process access the critical
section at a time.
BUT , in the dining philosophers problem more than one philosopher can acces
the critical section if they are independent to each other.
For example:-
p0,p2 p1,p3 p2,p4 p5,p1
These pair can eat at same time.
1st Condition:-
If all the adjacent philosopher are about to eat
one after one ,then the alternative group can eat
together,
After that remaining philosopher can eat.
2nd Condition:-
• All philosopher are willing to have food together aat same time.
• And they all have to execute code of entry.
• At the time of 1st clock cycle they will get their left fork f(i)
successfully.
• But at time of 2nd clock cycle when philosophers will try to have
ther right side placed spoon, they all(philosopher will blocked) ,
because all spoons are consumed by previous philosopher.
• So here DEADLOCK occurs .

dinning phillosopher problem

  • 1.
  • 2.
    Changes in functionof code while accesing food by philosophers….. • Void Philosopher(Void) • { • While(true) • { • Thinking(), • Wait(Take-spoon(i)), • Wait(Take-spoon((i+1)%N)), • EAT(), • Signal(Put-spoon(i)), • Signal(Put spoon((i+1)%N)), • } • }
  • 3.
    Here to solvedp problem ,we will use N no of Binary Semaphores.. • S[i] • N=no of spoons • So here we will use 5 semaphores • all the semaphores are initialized with 1 •S0 , S1 , S2 , S3 , S4 1 1 1 1 1
  • 4.
    Philosopher need whatsemaphore as value 1 at which time? philosopher 1st clock cycle semaphore 2nd clock cycle semaphore p0 s0 s1 p1 s1 s2 p2 s2 s3 p3 s3 s4 p4 s4 s0
  • 5.
    Exception of MUTUALEXCLUSION MUTUAL EXCLUSION- there can be only one process access the critical section at a time. BUT , in the dining philosophers problem more than one philosopher can acces the critical section if they are independent to each other. For example:- p0,p2 p1,p3 p2,p4 p5,p1 These pair can eat at same time.
  • 6.
    1st Condition:- If allthe adjacent philosopher are about to eat one after one ,then the alternative group can eat together, After that remaining philosopher can eat.
  • 7.
    2nd Condition:- • Allphilosopher are willing to have food together aat same time. • And they all have to execute code of entry. • At the time of 1st clock cycle they will get their left fork f(i) successfully. • But at time of 2nd clock cycle when philosophers will try to have ther right side placed spoon, they all(philosopher will blocked) , because all spoons are consumed by previous philosopher. • So here DEADLOCK occurs .