狗仔队
这个跟那个独木桥问题一样的吧。semaphore mutexAB, mutexA, mutexB;mutexAB=1; //互斥信号量,用于两组小朋友之间的互斥mutexA=1; //互斥信号量,用于访问共享变量countA的互斥mutexB=1; //互斥信号量,用于访问共享变量countB的互斥int countA, countB;countA=0; //用于A组小朋友计数countB=0; //用于B组小朋友计数 parbeginprocess groupA ( ) //A组小朋友进程,i=1, 2, ... , n{P(mutexA);if (countA==0) P(mutexAB);countA++;V(mutexA);通过窄垫子;P(mutexA);countA--;if (countA==0) V(mutexAB);V(mutexA); }process groupB ( ) //B组小朋友进程,j=1, 2, ... , m{P(mutexB);if (countB==0) P(mutexAB);countB++;V(mutexB);通过窄垫子;P(mutexB);countB--;if (countB==0) V(mutexAB);V(mutexB); }parend