计算机操作系统第四版汤小丹版
@. 试修改下面生产者——消费者问题解法中的错误:
producer: consumer:
begin begin
repeat repeat
produce an item in nextp; wait(mutex);
wait(mutex); wait(empty);
wait(full); nextc:=buffer(out);
buffer(in):=nextp; out:=out+1;
signal(mutex); signal(mutex);
until false; consume item in nextc; end until false;
end
@. 试利用记录型信号量写出一个不会出现死锁的哲学家进餐问题的算法。 三种解决方法中的任意一种即可(略)。P62
@. 在测量控制系统中的数据采集任务时,把所采集的数据送往一单缓冲区;计算任务从该单缓冲区中取出数据进行计算。试写出利用信号量机制实现两任务共享单缓冲区的同步算法。
a. Var mutex, empty, full: semaphore:=1, 1, 0;
gather:
begin
repeat
gather data in nextp;
wait(empty);
wait(mutex);
buffer:=nextp;
signal(mutex);
signal(full);
until false;
end compute: begin repeat wait(full); wait(mutex); nextc:=buffer; signal(mutex); signal(empty); compute data in nextc; until false; end
compute:
begin
repeat
wait(full);
nextc:=buffer;
signal(empty);
compute data in nextc;
until false;
end b. Var empty, full: semaphore:=1, 0; gather: begin repeat gather data in nextp; wait(empty); buffer:=nextp; signal(full); until false; end
@. 试比较进程间的低级通信工具与高级通信工具.