Ask a Question

how can semaphore be used to enforce mutual exclusion?

on 2011-09-08 10:22:27   by pritha   on BCA  1 answers

sanchayita

on 2011-09-08 09:30:00  

semaphore is a variable providing mutual exclusion in following manner- -It consist of two function called wait and signal, wait() { while(semav==0); semav--; } signal() { semav++; } where semav is semaphore. we apply wait() and signal() in following manner- while(true) { ; wait() signal() } note that wait() always comes before signal(), a process is not allowed to execute critical section if the semaphore has a value 0 i.e. at most one process can execute critical section at a time.