进程管理复习资料 联系客服

发布时间 : 星期六 文章进程管理复习资料更新完毕开始阅读

end

第 9 页 共 36 页

29、画图说明管程由哪几部分组成?(P56)为什么要引入条件变量?(P57) 【解】如图:

条件(不忙)队列 共享数据 进入队列 …… 一组操作进程 初始化代码 通常,由于等待的原因可能有多个,为了区别它们,因此引入条件变量。

第 10 页 共 36 页

30、如何利用管程来解决生产者—消费者问题?(P60) 【解】首先为它们建立一个管程,描述如下: Type producer-consumer=monitor var in, out, count: integer;

buffer: array[0,-----,n-1] of item; notfull,notempty:condition; procedure entry put(item) begin

if count>=n then notfull.wait; buffer(in):=nextp; in:=(in+1) mod n; count:=count+1;

if notempty.queue then notempty.signal; end

procedure entry get(item) begin

if count<=0 then notempyt.wait; nextc:=buffer(out); out:=(out+1) mod n; count:=count-1;

if notfull.queue then notfull.signal; end

begin in:=out:=0; count:=0; end

生产者和消费者可描述为: producer: begin

repeat

produce an item in nextp; PC.put(item); until false; end

consumer: begin repeat

PC.get(item);

consume the item in nextc until false; end

第 11 页 共 36 页

31、什么是AND信号量?试利用AND信号量写出生产者—消费者问题的解法。

【解】AND信号量是指:将进程在整个运行过程中所需的所有临界资源一次性地全部分配给进程,待该进程使用完后再一起释放。只要尚有一个资源未能分配给该进程,其他所有可能为之分配的资源,也不分配给他,即:对若干临界资源分配,采取原子操作方式,要么全部分配到进程,要么一个也不分配。叫AND信号量。 解法如下:

var mutex,empty,full:semaphore:=1,n,0; buffer: array[0,---,n-1]of item; in,out:integer:=0,0; begin

parbegin

producer: begin repeat

produce an item in nextp Swait(empty,mutex); buffer(in):=nextp; in:=(in+1)mod n; Ssignal(mutex,full); until false; end consumer: begin repeat

Swait(full,mutex); nextc:=buffer(out); out:=(out+1)mod n; Ssignal(mutex,empty);

consume the item in nextc; until false

end;

32、什么是信号量集?试利用信号量集写出读者-写者问题的解法。

33、试比较进程间的低级与高级通信工具。(P65)

34、当前有哪几种高级通信机制?(P65)

【解】共享存储器系统,消息传递系统,管道通信系统。

35、消息队列通信机制有哪几方面功能?(P66)

【解】发送进程利用send原语,将消息直接发送给接收进程;接收进程利用receive原语接收消息。

36、为什么要在OS中引入线程?(P72) 【解】

第 12 页 共 36 页