

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Spring 2006 Homework 3
Due date: 03/14/
Grade: 7% of your final grade is allocated for this homework.
Submission deadline: This homework is due in class on March 14, 2006.
What to submit: Submit a hardcopy of your answers.
int x = 10; y = 15; semaphore s1 = 1, s2 = 1;
P1: { P(s1); x = x+1; P(s2); x = x * y; y = y-5; V(s2); V(s1);}
P2: { P(s2); y = 10; V(s2); P(s1) x = 0; V(s1);}
P3: { P(s1); P(s2); x = y*10; V(s2); V(s1);}
(a) [20 Points] Use semaphores to design your algorithm. Do not worry about starvation in your design. (b) [15 Points] Modify your solution in (a) to avoid starvation. Because cleanliness is important, design your algorithm in such a way that it gives preference to the janitor and treats all other individuals equally.