文章
7
粉丝
0
获赞
0
访问
427
semaphore mutex=1;//互斥使用水井
semaphore mutex2=1;//互斥使用水缸
semaphore bucket=3;//水桶数目
semaphore full=0;//水缸中水的数目
semaphore empty=10;//水缸剩余容量
小和尚(){
while(1){
p(empty);
p(bucket);
p(mutex);
get water;
v(mutex);
p(mutex2);
pour water;
v(mutex2);
v(full);
v(bucket);
}
}
老和尚(){
while(1){
p(full);
p(bucket);
p(mutex2);
get water;
v(mutex2);
v(empty);
v(bucket);
}
}
评分及理由
(1)得分及理由(满分8分)
该学生的答案基本正确,与标准答案在逻辑上一致,但在信号量的命名上有所不同(如mutex和mutex2代替mutex_well和mutex_vat),但这不影响逻辑的正确性。因此,可以给予满分8分。
题目总分:8分
登录后发布评论
暂无评论,来抢沙发