题目是:有一个水果盘只能放一个水果,ABCD四个人,A往盘中放苹果,B往盘中放梨,C从盘中取苹果,D从盘中取梨
int mutex=1,apple=0,pear=0,empty=1;///一共4个信号量;
A: wait(mutex);
wait(empty);
signal(apple);
signal(mutex);
B: wait(mutex);
wait(empty);
signal(pear);
signal(mutex);
C: wait(mutex);
wait(apple);
signal(empty);
signal(mutex);
D: wait(mutex);
wait(pear);
signal(empty);
signal(mutex);