文章
5
粉丝
0
获赞
0
访问
229
Semaphore bucket = 3; // 水桶数:最多允许3人同时持桶操作
Semaphore well = 1; // 水井:井口一次只能一个桶取水
Semaphore empty = 10; // 缸中空位数(最多10桶)
Semaphore full = 0; // 缸中已有的水桶数
Semaphore mutex = 1; // 操作缸时的互斥信号量
do {
P(bucket); // 申请一个水桶
P(well); // 进入水井口
// 取水(提水时间)
V(well); // 离开井口
P(empty); // 等待缸中有空位
P(mutex); // 进入临界区操作水缸
// 将水倒入缸中
V(mutex); // 离开临界区
V(full); // 增加缸中水量
V(bucket); // 归还水桶
} while (true);
do {
P(full); &...
登录后发布评论
暂无评论,来抢沙发