(Philosophor1) 1 AND (Buffers001) 1 AND (Philosophor1) 2 From Buffers001

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Bonus Question 2

Problem:

There are 5 philosophers (who only eat and think) and 5 forks. Each philosopher can eat only using 2
forks. As each philosopher is unaware of the other 4 philosophers’, one or more philosophers can end
up starving or there can be a dead lock if each philosopher is only able to pick one fork. This is a
synchronization problem.

Solution 1:

In my first program, I have taken part with lot size=5. These parts are referred to as forks. I have taken 5
machines in batch, each can process a min of 1 part and max of 2 parts. The parts go to a buffer. The
machines pull these parts using Pull rule defined as
IF IState (Philosophor1) = 1 AND NParts (Buffers001) > 1 AND NParts (Philosophor1) < 2
PULL from Buffers001
ELSE
Wait
ENDIF

Inside Machines details, I have added a line under setup tab, labelled as Thinking. The machine
undergoes setup each time the philosopher finishes eating. The program runs fine in Witness and shows
no errors. However, in actual, this can create synchronization problems in the initial few minutes of
running of the program.

Solution 2:

In my second program, I have taken 5 buffers each having one part. I have taken 5 machines again. In
the pull rule, the first machine can pull only from buffer 1 and 2. Similarly second machine cab pull only
from buffers 2 and 3. The other machines pull in a similar way. In the first cycle, each machine pulls the
lowest number of part e.g first machine will pull from buffer 1 in the first cycle and not from buffer 2.
The other machines pull in a similar way in the first cycle. Fifth machine will not be able to pull as the
lowest of the two (5 and 1) which is 1 is already taken by machine 1. Now begins the second cycle. In the
second cycle, each machine will try to pull the max number e.g machine 1 will try to pull from buffer 2 if
the part is available. In this cycle, the part will be only available to machine 1 and not to others as the
max for other machines has already been taken in the first cycle. So it can be said that philosopher 1 is
able to eat. These 2 cycles will repeat and in the second time, only machine 2 will be able to acquire 2
parts. The other machines will be able to aquire parts similarly in the next cycles. My pull rule is

IF N = 1 AND IState (Machine001(1)) = 1 AND NParts (Fork1) = 1 AND NParts (Machine001(1)) < 1
PULL from Fork1
ELSEIF N = 2 AND IState (Machine001(2)) = 1 AND NParts (Fork2) = 1 AND NParts (Machine001(2)) < 1
PULL from Fork2
ELSEIF N = 3 AND IState (Machine001(3)) = 1 AND NParts (Fork3) = 1 AND NParts (Machine001(3)) < 1
PULL from Fork3
ELSEIF N = 4 AND IState (Machine001(4)) = 1 AND NParts (Fork4) >= 1 AND NParts (Machine001(4)) < 1
PULL from Fork4
ELSEIF N = 5 AND IState (Machine001(5)) = 1 AND NParts (Fork5) >= 1 AND NParts (Machine001(5)) < 1
PULL from Fork1
ELSEIF N = 1 AND IState (Machine001(1)) = 1 AND NParts (Fork2) = 1 AND NParts (Machine001(1)) = 1
PULL from Fork2
ELSEIF N = 2 AND IState (Machine001(2)) = 1 AND NParts (Fork3) = 1 AND NParts (Machine001(2)) = 1
PULL from Fork3
ELSEIF N = 3 AND IState (Machine001(3)) = 1 AND NParts (Fork4) = 1 AND NParts (Machine001(3)) = 1
PULL from Fork4
ELSEIF N = 4 AND IState (Machine001(4)) = 1 AND NParts (Fork5) = 1 AND NParts (Machine001(4)) = 1
PULL from Fork5
ELSEIF N = 5 AND IState (Machine001(5)) = 1 AND NParts (Fork1) = 1 AND NParts (Machine001(5)) = 1
PULL from Fork5
ELSE
Wait
ENDIF

You might also like