how to answer this question, thanks# Programming - 葵花宝典
y*h
1 楼
It should be possible to implement general semaphores using binary
semaphores. We can use the operations semWaitB and semSignalB and two
binary semaphores, delay and mutex. Consider the following:
01 Semaphore mutex = 1;
02 Semaphore delay = 0;
03
04 void semWait (semaphore s)
05 {
06 semWaitB(mutex);
07 if (--s < 0)
08 {
09 semSignalB(mutex);
10 semWaitB(delay);
11 }
12 else
13 semSignalB(mutex);
14 }
15
16
semaphores. We can use the operations semWaitB and semSignalB and two
binary semaphores, delay and mutex. Consider the following:
01 Semaphore mutex = 1;
02 Semaphore delay = 0;
03
04 void semWait (semaphore s)
05 {
06 semWaitB(mutex);
07 if (--s < 0)
08 {
09 semSignalB(mutex);
10 semWaitB(delay);
11 }
12 else
13 semSignalB(mutex);
14 }
15
16