云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 计算机操作系统第四版课后习题答案

计算机操作系统第四版课后习题答案

  • 62 次阅读
  • 3 次下载
  • 2025/5/1 3:27:38

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 compute: begin repeat …… wait(full); nextc:=buffer; signal(empty); compute data in nextc; until false; end

29.画图说明管程由哪几部分组成,为什么要引入条件变量?

答:管程由四部分组成:①管程的名称;②局部于管程内部的共享数据结构说明;③对该数 据结构进行操作的一组过程;④对局部于管程内部的共享数据设置初始值的语句; 当一个进程调用了管程,在管程中时被阻塞或挂起,直到阻塞或挂起的原因解除,而在此期 间,如果该进程不释放管程,则其它进程无法进入管程,被迫长时间地等待。为了解决这个 问题,引入了条件变量condition。

30.如何利用管程来解决生产者与消费者问题?

答:首先建立一个管程,命名为ProclucerConsumer,包括两个过程:

(1)Put(item)过程。生产者利用该过程将自己生产的产品放到缓冲池,用整型变

量count 表示在缓冲池中已有的产品数目,当count≥n 时,表示缓冲池已满,生产者须 等待。

(2)get(item)过程。消费者利用该过程从缓冲池中取出一个产品,当count≤0 时,表示缓冲池中已无可取的产品,消费者应等待。 PC 管程可描述如下:

type producer-consumer =monitor Var in,out,count:integer; buffer:array[0,…,n-1]of item; notfull,notempty:condition; procedure entry dot(item) begin

if count>=n then not full.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 not full.wait; nextc:=buffer(out); out:=(out+1)mod n; count:=count-1;

if notfull.quene then notfull.signal; end

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

在利用管程解决生产者一消费者问题时,其中的生产者和消费者可描述为: producer: begin pepeat

produce an inem in nestp PC.put(item);

until false; end

consumer: begin repeat PC.get(item);

consume the item in enxtc; until false; end

31.什么是AND信号量?试利用AND信号量写出生产者一消费者问题的解法。 答:为解决并行带来的死锁问题,在wait 操作中引入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; …

wait(empty);

wait(s1,s2,s3,...,sn); //s1,s2,...,sn为执行生产者进程除empty 外其余的条件 wait(mutex); buffer(in):=nextp; in:=(in+1) mod n; signal(mutex); signal(full);

signal(s1,s2,s3,...,sn); until false; end

consumer: begin

repeat wait(full);

wait(k1,k2,k3,...,kn); //k1,k2,...,kn 为执行消费者进程除full 外其余的条件 wait(mutex); nextc:=buffer(out); out:=(out+1) mod n; signal(mutex); signal(empty);

signal(k1,k2,k3,...,kn); consume the item in nextc; until false; end parend end

32.什么是信号量集?试利用信号量集写出读者一写者问题的解法。 答:对AND信号量加以扩充,形成的信号量集合的读写机制。 解法:Var RN integer; L,mx: semaphore:=RN,1; begin parbegin reader:begin repeat Swait(L,1,1); Swait(mx,1,1); …

perform read operation; …

Ssignal(L,1); until false end

writer:begin repeat

Swait(mx,1,1;L,RN,0);

搜索更多关于: 计算机操作系统第四版课后习题答案 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

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 compute: begin repeat …… wait(full); nextc:=buffer; signal(empty); compute data in nextc; until false; end 29.画图说明管程由哪几部分组成,为什么要引入条件变量? 答:管程由四部分组成:①管程的名称;②局部于管程内部的共享数据结构说明;③对该数 据结构进行操作的一组

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com