Problem 8: i) In some office space, there can be in the room either only the emp
ID: 3702947 • Letter: P
Question
Problem 8: i) In some office space, there can be in the room either only the employees that work there or the cleaning personnel that supervise and sterilize the office space. The employees work into their office for a window of time (working_window()) and then take periodically a break outside the office (break_time()). The cleaning personnel never enter the office while there are still employees there. And vice versa, the employees do not enter the office while members of the cleaning personnel are still cleaning and tidying up the offices The employees are represented by threads that execute function employee() and the cleaning personnel are represented by threads which execute function cleaner() void employee() void cleaner() while (true) f while (true) t working_window ; clean_office); break time); break_time(); paces, such that the You are requested to implement synchronization schemes in the dotteds working mode that was described above is ensured. You may use: signal() and wait() calls to properly initialized semaphores and any shared variables among the required threads/ processes. Please justify if there is any possibility of starvation in the solution you provided. ii The office space described above acquires exactly N employees seating/working space. Please modify the synchronization scheme you built for i) so that at most N employees can exist at the office space at the same time, hence at most N threads execute function working_window() at the same time iii)Assume that more cleaning personnel is hired, who can all work together at the same time in the office space, as long as no employees are present. Modify the synchronization scheme you developed for ii) so that at the office space there can be either: at most N employees or at most M members of the cleaning personnel. Solution:Explanation / Answer
i) In this solution there is a semaphore initialized to 1 such that whenever employees enter into working_window this s is decreased to 0 and thus if cleaning person tries to enter into clean_office will have to wait as s=0
s = 1;
void employee(){
while(true){
P(s);
working_window();
V(s);
break_time();
}
}
void cleaner(){
while(true){
P(s);
clean_office();
V(s);
break_time();
}
}
P(semaphore s){
while(s <= 0);
s--;
}
V(semaphore s){
s++;
}
Starvation is possible as there is no preemption from CS possible in this solution, either employees or cleaning staff can starve the other one.
ii) To modify above solution to accommodate at most N employee requirements, add anothe variable empNo and initialize it to N, now employee can execute working_window only if no cleaners are there and also if less than N employees present in the work space
s = 1;
empNo = N
void employee(){
while(true){
P(s);
P(empNo)
working_window();
V(empNo)
V(s);
break_time();
}
}
void cleaner(){
while(true){
P(s);
clean_office();
V(s);
break_time();
}
}
P(semaphore s){
while(s <= 0);
s--;
}
V(semaphore s){
s++;
}
iii) Similar to ii) add another variable to keep track of number of cleaner clnNo initialized to M
s = 1;
empNo = N
clnNo = M
void employee(){
while(true){
P(s);
P(empNo)
working_window();
V(empNo)
V(s);
break_time();
}
}
void cleaner(){
while(true){
P(s);
P(clnNo);
clean_office();
V(clnNo);
V(s);
break_time();
}
}
P(semaphore s){
while(s <= 0);
s--;
}
V(semaphore s){
s++;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.