Question: Chapter 6, Problem 18 Operating Systems: Internals and Design Principles Systems, 7th Edition (Textbook Solutions) Author: William Stallings ______________ Suppose that there are two types

Chapter 6, Problem 18

Operating Systems: Internals and Design Principles Systems, 7th Edition (Textbook Solutions)

Author: William Stallings

______________

Suppose that there are two types of philosphers. One type always picks up his left fork first (a "lefty"), and the other type always picks up his right fork first (a "righty"). The behavior of a left is defined in Figure 6.12. The behavior of a righty is as follows:

begin

repeat

think;

wait (fork[(i+1) mod 5]);

wait (fork[i]);

eat;

signal (fork[i]);

signal (fork[(i+1) mod 5]);

forever

end;

Prove the following:

a. Any seating arrangement of lefties and righties with at least one of each avoids deadlock.

b. Any seating arrangement of lefties and righties with at least one of each prevents starvation.

Figure 6.12

------------------------

/*program dining philopsheres*/

semaphore fork [5] = {1};

int i;

void philosopher (int i){

while(true){

think();

wait( fork [i]);

wait( fork [(i+1) mod 5]);

eat();

signal (fork [(i+1) mod 5]);

signal (fork[i]);

}

}

void main(){

parbegin (philosopher (0), philosopher (1), philosopher (2), philosopher (3), philosopher (4));

}

-----------------------

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!