Semaphore Implementation with no Busy waiting o With each semaphore there is an associated waiting queue.Each entry in a waiting queue has two data items: value (of type integer) pointer to next record in the list o Two operations: block-place the process invoking the operation on the appropriate waiting queue. wakeup-remove one of processes in the waiting queue and place it in the ready queue
Semaphore Implementation with no Busy waiting With each semaphore there is an associated waiting queue. Each entry in a waiting queue has two data items: value (of type integer) pointer to next record in the list Two operations: block – place the process invoking the operation on the appropriate waiting queue. wakeup – remove one of processes in the waiting queue and place it in the ready queue
Semaphore Implementation with no Busy waiting (Cont.) o Implementation of acquire(): acquire(){ value--; if (value 0){ add this process to list block; o Implementation of release(: release(){ value++; if (value <=0){ remove a process P from list wakeup(P);
Semaphore Implementation with no Busy waiting (Cont.) Implementation of acquire(): Implementation of release():
Mutual Exclusion with Semaphores semaphore mutex 1; cobegin /1 pi:while (1){ mutex.acquire(); CSi; mutex.release(); programi; // coend
Mutual Exclusion with Semaphores semaphore mutex = 1; cobegin ... // pi: while (1) { mutex.acquire(); CSi; mutex.release(); programi; } // ... coend;