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

Man, I can see why you are confused. The problem here is that this example merges two concepts.
A semaphore is a form of mutex. In the abstract, a mutex is just a variable that can be atomically incremented or decremented. Your up function increments. Your down function decrements event if multiple process are up'ing or down'ing at the same time. If you just make up equivalent to count = count + 1 you would get random results if multiple processes tried to increment at the same time.
In the real world (outside academia) a semaphore does more than just increment. You can wait on a semaphore as well.
So, if I do
My process decrements the semaphore. If no process (or thread) has locked the semaphore (usually = 0, with 1 being the starting point), my process continues. If another process has already locked the semaphore (value after down < 0), my process waits.
When the process that has locked the semaphore finishes and does
The operating system picks one of the waiting processes to run automatically.
Thus your Hoare monitor looks like
Or we could write it as:
That's the monitor part. The part about your example that is confusing is that it is a poorly written lock/unlock using academic semaphores that just increment and decrement atomically and have no knowledge of who is waiting on them.
It's wait is equivalent to my lock. It's equivalent to my unlock is totally FUed.
At this point I would leave as an exercise for you to create a lock function that will only allow one process/thread to acquire the lock using a pair of semaphores but will allow multiple processes to wait and, when unlocked, will allow one waiting process/thread to continue.
It needs an unlock function that will unlock the mutex pair to allow one process/thread to continue.