请在 下方输入 要搜索的题目:

试修改下面生产者-消费者问题解法中的错误(重新写出完整的代码): Var mutex,full,empty : semaphore:=1,0,n;//n是缓冲区单元格总数 producer: begin repeat ... producer an item in nextp; wait(mutex); wait(full); buffer(in):=nextp; signal(mutex); until false; end consumer: begin repeat wait(mutex); wait(empty); nextc:=buffer(out); out:=out 1; signal(mutex); consumer item in nextc; until false; end

试修改下面生产者-消费者问题解法中的错误(重新写出完整的代码): Var mutex,full,empty : semaphore:=1,0,n;//n是缓冲区单元格总数 producer: begin repeat ... producer an item in nextp; wait(mutex); wait(full); buffer(in):=nextp; signal(mutex); until false; end consumer: begin repeat wait(mutex); wait(empty); nextc:=buffer(out); out:=out 1; signal(mutex); consumer item in nextc; until false; end

发布时间:2025-06-18 10:10:18
推荐参考答案 ( 由 快搜搜题库 官方老师解答 )
联系客服
答案:Var mutex,full,empty : semaphore:=1,0,n;//n是缓冲区单元格总数 producer: begin repeat ... producer an item in nextp; wait(mutex); wait(full); /* 应为wait(empty),而且还应该在wait(mutex)的前面 */ buffer(in):=nextp; /* 缓冲池数组游标应后移,这里加上这一行: in:=(in 1) mod n; */ signal(mutex); /* 加上这一行: signal(full); */ until false; end consumer: begin repeat wait(mutex); wait(empty); /* 应为wait(full),而且还应该在wait(mutex)的前面 */ nextc:=buffer(out); out:=out 1; /* 考虑循环,应改为: out:=(out 1) mod n; */ signal(mutex); /* 这里加上这一行: signal(empty); */ consumer item in nextc; until false; end【单选题】当事人之间不存在管辖协议时,下列关于民事诉讼地域管辖的表述中,不符合民事诉讼法律制度规定的是()。
专业技术学习
专业技术学习
搜搜题库系统