it is my exam in 4 days and I just spoke to my lectuer and he has been extremely unclear about this part of the lecture and I really struggled along with many students how to understand this.
Basiclly, if you wanna implement Hoare monitor using semaphore, what is the sequences of steps involved?
]3
Update:
I am starting to get it now
so the 1st slide is for the process accessing the monitor
if you are the only one, then you call wait(mutex)
get into the monitor do your stuff and leave
if there is something waiting to get into the monitor then you up the next semaphore, that is the quene of waiting process to get into the semaphore. else if you are the only one in the monitor then you exit and up mutex so someone else can get into the mutex
for the 2nd slide with the wait(condition) and signal(condition)
when u wait(c): c_count++ //number of process waiting for this condition, increment by one if(next_count>0) up(next) //if number of waiting process that want t get into the monitor is more than zero, up(next), unblock one of the waiting process
else up(mutex) //if you are the only one then up mutex so someone else get in down(c_sem) // block yourself to sleep c_count-- //you wake up so number of process waiting for this condition decrement
for the signal(c) part:
if(c_count>0) // if number of process waiting for this condition is bigger than 0
next_counter++ //number of process wanting to get into the monitor increment by one up(c_sem); // unblock one of the process waiting for this condition down(next) //if a spot is available, down this otherwise get block and join list of waiting processes next_count--; //you wake up and try to get into the monitor