multithreading - Using semaphore , Sync two threads Patient and Assistant -


i asked question in interview prestigious group in company(i cannot tell name) stack question while, generated possible solutions them want make sure solution correct, please comment or fix solution or guide me solution or show if solution has deadlock, starvation etc...,

this problem:

patients go bio lab work. lab contains nummachines. in lab there supervisor assign 1 machine each patient if there available machines. after patient finishes work, releases machine , waits until 2 patients done. when group has 3 patients formed leave.

use semaphores , operations on semaphores, synchronize 2 types of threads: patient , supervisor

binary semaphore mutex=1  counting semaphore machine =5 , done =0  patient:  p(machine);  v(done); p(mutex);  waitingpatient++;  if(waitingpatient==groupsize){     for(int i=0’i<groupsize;i++){         v(waiting); }  waitingpatient=0; p(waiting); v(mutex); }  else{     p(waiting);     v(mutex); }  assistant:  while(true){     p(done);     v(machine); } 


Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -