条单向行驶的公路上有一座桥,该桥只允 许一辆汽车在桥上行驶,当桥上有汽车时,其 它汽车不能上桥。 (There is a bridge on a one-way road.Only one car is allowed to drive on the bridge at a time.If there is a car on the bridge,other cars are not allowed to go through the bridge.) 互斥还是同步?(mutex or cooperation?) 信号量及初值?(semaphore and the initial value?) 实现过程? 6
6 练习: 在一条单向行驶的公路上有一座桥,该桥只允 许一辆汽车在桥上行驶,当桥上有汽车时,其 它汽车不能上桥。 (There is a bridge on a one-way road. Only one car is allowed to drive on the bridge at a time. If there is a car on the bridge, other cars are not allowed to go through the bridge.) 互斥还是同步?(mutex or cooperation?) 信号量及初值?(semaphore and the initial value?) 实现过程?
■互斥问题 ■S=1 汽车进程pi(i=0,1,2,…) acquire(s) 汽车上桥 汽车下桥 release(s) 7
7 互斥问题 s=1 汽车进程pi (i=0,1,2,…) acquire(s) 汽车上桥 汽车下桥 release(s)