由买买提看人间百态

topics

全部话题 - 话题: semwaitb
(共0页)
y*h
发帖数: 107
1
来自主题: Programming版 - how to answer this question, thanks
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
(共0页)