void semWait (s) { if (s.count > 0){ s.count --; } else{ place this process in s.queue; block; } } void semSignal (s) { if (there is at least one process blocked on semaphore){ remove a process P from s.queue; place process P on ready list; } else s.count++; }
将该定义与图 5.3 中的定义进行比较,得出两个定义之间有一个区别:在前面的定义中,信号量永远不会取负值。在程序中分别使用这两种定义时,其效果有何不同?即能否在不改变程序意义的前提下,用一个定义代替另一个?