Semaphore by Dijkstra and why is it undesirable?


  • 0
    W

    Provide the definition of a semaphore by Dijkstra. The implementation based on this definition leads to the issue of “busy waiting”. What is this problem and why is it undesirable?


  • 0
    W

    The question is no difficult.

    wait(s)
    {
       while (s <= 0)
                 ; // no-op
       s--;
    }
    
    signal(s)
    {
       s++;
    }
    

    The above implementation leads to busy waiting: processes waiting on the wait () continuously perform a while loop () until they can enter the critical section. This is undesirable because processor cycles are being wasted, which ideally could be used by other processes which are simultaneously ready to execute in the system.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.