CSP-chapter2

# Phil2 phil3 phil4 and they were disposed in this

• Notes
• 55

This preview shows pages 15–23. Sign up to view the full content.

PHIL2, PHIL3, PHIL4, and they were disposed in this order anticlockwise around the table. To the left of each philosopher there was laid a golden fork, and in the centre stood a large bowl of spaghetti, which was constantly replenished. A philosopher was expected to spend most of his time thinking; but when he felt hungry, he went to the dining room, sat down in his own chair, picked up his own fork on his left, and plunged it into the spaghetti. But such is the tangled nature of spaghetti that a second fork is required to carry it to the mouth. The philosopher therefore had also to pick up the fork on his right. When he was finished he would put down both his forks, get up from his chair, and continue thinking. Of course, a fork can be used by only one philosopher at a time. If the other philosopher wants it, he just has to wait until the fork is available again. 15

This preview has intentionally blurred sections. Sign up to view the full version.

& \$ % Diagram for Illustrating the Example Please see page 57 (i.e., 79) of the book. 16
& \$ % Alphabets of the Example (1) For PHIL i , its alphabet is defined: αPHIL i = { i.sits down, i.gets up, i.picks up fork.i, i.picks up fork. ( i 1) , i.puts down fork.i, i.puts down fork. ( i 1) } (2) For the i -th fork, its alphabet is defined as: αFORK i = { i.picks up fork.i, ( i 1) .picks up fork.i, i.puts down fork.i, ( i 1) .puts down fork.i } 17

This preview has intentionally blurred sections. Sign up to view the full version.

& \$ % Behavior of the Example (1) Apart from thinking and eating which we have chosen to ignore, the life of each philosopher is described as the repetition of a cycle of six events PHIL i = ( i.sits down i.picks up fork.i i.picksupfork. ( i 1) i.puts down fork.i i.puts down fork. ( i 1) i.gets up PHIL i ) (2) The role of a fork is a simple one; it is repeatedly picked up and put down by one of its adjacent philosophers (the same one on both occasions) 18
& \$ % FORK i = ( i.picks up fork.i i.puts down fork.i FORK i | ( i 1) .picks up fork.i ( i 1) .puts down fork.i FORK i ) (3) The behaviour of the whole College is the concurrent combination of the behaviour of each of these components PHILOS = ( PHIL 0 || PHIL 1 || PHIL 2 || PHIL 3 || PHIL 4 ) FORKS = ( FORK 0 || FORK 1 || FORK 2 || FORK 3 || FORK 4 ) COLLEGE = PHILOS || FORKS 19

This preview has intentionally blurred sections. Sign up to view the full version.

& \$ % Variation of the Example (1) Variation 1 An interesting variation of this story allows the philosophers to pick up their two forks in either order, or put them down in either order. Consider the behaviour of each philosophers hand separately. Each hand is capable of picking up the relevant fork, but both hands are needed for sitting down and getting up 20
& \$ % αLEFT i = { i.picks up fork.i, i.puts down fork.i, i.sits down, i.gets up } αRIGHT i = { i.picks up fork. ( i 1) , i.puts down fork. ( i 1) , i.sits down, i.gets up } LEFT i = ( i.sits down i.picks up fork.i i.puts down fork.i i.gets up LEFT i ) RIGHT i = ( i.sits down i.picks up fork. ( i 1) i.puts down fork. ( i 1) i.gets up RIGHT i ) PHIL i = LEFT i || RIGHT i 21

This preview has intentionally blurred sections. Sign up to view the full version.

& \$ % (2) Variation 2 In yet another variation of the story, each fork may be picked up and put down many times on each occasion that the philosopher sits down. Thus the behaviour of the hands is modified to contain an iteration, for example LEFT i = ( i.sits down
This is the end of the preview. Sign up to access the rest of the document.
• Fall '12
• ZhuHuibiao
• Continuous function, ST OP

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern