3,340 views
2 votes
2 votes
what is true about binary semaphore?

1)Binary semaphore has drawback called busy wait or spin lock.

2)Binary semaphore is applicable only for two processes

3)Binary semaphore has no drawback called busy wait or spin lock

4)none of the above

5 Answers

3 votes
3 votes
For 1) and 3) from galvin and wikipedia, it says that

"Traditional semaphore has drawback of busy waiting aka spinlock but In a slightly modified implementation which is using the Queue overcome this problem" So 1) and 3) both are depends on implemenation.

For 2) although binary semaphor is applicable for only 2 processes but we can implement counting semaphor using Binary semaphor.
0 votes
0 votes
  Answer should be (3)    struct Bsemaphore  {      enum value(0,1);      Queue type L;// list of all processes get                    // blocked while performing down operation usuccessfully         }    Bsemaphore s:  s.value=1;  Down(s);    Down(Bsemaphore s)  {      if(s.value==1)      {          s.value=0;      }      else      {          put the process in s.L and block it          sleep();      }  }      Up(Bsemaphore s)  {      if(s.L() is empty)      {          s.value=1;      }      else      {          select a process from s.L(only one process)          wakeup();      }  }
0 votes
0 votes
i think there is no such drawback instead it uses a diffrent mechanism which was made to overcome the problem of busy wait and spin lock . which is sleep procedure till someone is inside the critical section don't knock at the door just go to sleep when there will be a space the process will wake u up . the process of busy waiting is a charterstic  of lock variable not of semaphonre

Related questions

1 votes
1 votes
2 answers
3
sumit chakraborty asked Nov 26, 2017
984 views
Given Processes P1: Wait(Sx); Wait(Sy); Do something;Signal(Sx); Signal(Sy); and Process P2: Wait(Sx); Wait(Sy); Do something;Signal(Sy); Signal(Sx); . Will it ever lead ...
0 votes
0 votes
4 answers
4
piyushkr asked Jan 21, 2016
1,584 views
Up(Semaphore S) { if (Suspended list() is empty) S.value=1; else { Select a process from the suspended list and WakeUp() } }