呵呵,我也很郁闷这个问题
还有一个问题是 请解释为什么两及调度比较常用
Associated with each counting semaphore are two binary semaphores, M,
used for mutual exclusion, and B, used for blocking. Also associated with
each counting semaphore is a counter that holds the number of up s minus the
number of down s, and a list of processes blocked on that semaphore. To im-
plement down , a process first gains exclusive access to the semaphores,
counter, and list by doing a down on M. It then decrements the counter. If it
is zero or more, it just does an up on M and exits. If M is negative, the proc-
ess is put on the list of blocked processes. Then an up is done on M and a
down is done on B to block the process. To implement up , first M is down ed
to get mutual exclusion, and then the counter is incremented. If it is more
than zero, no one was blocked, so all that needs to be done is to up M. If,
however, the counter is now negative or zero, some process must be removed
from the list. Finally, an up is done on B and M in that order.
——来自英文版答案