摘要: ///4)信号量mutex用于互斥,初值为1int waiting=0 ; //等候理发的顾客数int chairs=n; //为顾客准备的椅子数semaphore customers=0, barbers=0,mutex=1;cobegin barber()beginwhile(TRUE); //理完一人,还有顾客吗?P(cutomers); //若无顾客,理发师睡眠P(mutex); //进程互斥waiting := waiting – 1; //等候顾客数少一个V(barbers); //理发师去为一个顾客理发V(mutex); //开放临界区cut-hair( ); //正在理发end 阅读全文
posted @ 2013-01-27 06:23 tobeforest 阅读(74) 评论(0) 推荐(0)