Difference between Counting and Binary Semaphores

前端 未结 3 1129
花落未央
花落未央 2020-12-02 18:51

What is the difference between Counting and binary semaphore.

What I have seen somewhere is that both can control N number of processes which have requested for a r

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-02 19:11

    The most basic difference between counting and binary semaphore is that:

    1. Binary semaphore cannot handle Bounded wait as its just a variable that hold binary value. Counting semaphore It can handle bounded wait as it has converted a variable into a structure with a Queue.
    2. Strcuture implementation Binary semaphore: int s;

      Counting Semaphore: Struct S { int s; Queue q; }

    Using the counting semaphore now process once gained the CS(Critical Section) now has to wait for the other to get the CS, so not a single process strave. Each process get a chance for CS.

提交回复
热议问题