生产者与消费者得问题描述
来源:互联网 发布:java二级考试 编辑:程序博客网 时间:2024/05/21 17:51
生产者_消费者问题(参考资料;计算机操作系统)
1:利用记录型信号量解决生产者与消费者问题:
Var mutext,empty,full:semaphore=1,n,0;
buffer :array[0,…,n-1] ofitem;
in out :interge:=0,0;
begin
parbegin
producer:begin
repeat
proceduceran item nextp;
wait(empty);
wait(mutex);
buffer(in):=nextp;
in=(in+1)mod n;
signal(mutex);
signal(full);
until false;
end
consumer:begin
repeat
wait(full);
wait(mutex);
nextc:=buffer(out);
out:=(out+1)mod n;
signal(empty);
signal(mutex);
consumerthe item in nextc;
until false;
end
parend
end
2:利用AND信号量解决生产者与消费者问题:
Var mutext,empty,full:semaphore=1,n,0;
buffer :array[0,…,n-1] ofitem;
in out :interge:=0,0;
begin
parbegin
producer:begin
repeat
proceduceran item nextp;
Swait(empty,mutex);
buffer(in):=nextp;
in=(in+1)mod n;
Ssignal(mutex.mutex);
utilfalse;
end
consumer:begin
repeat
Swait(full,mutex);
nextc:=buffer(out);
out:=(out+1)mod n;
Ssignal(empty,mutex);
consumerthe item in nextc;
until false;
end
parend
end
3:利用管程解决生产者与消费者问题:
(1):Pc管道可以描述为:
type producer-consumer=monitor
Varint,out,count :integer;
buffer:array[0,…,n-1] of item;
notfull,notempty:condition;
proceducerentry put(item);
begin
if(count>=n)then notfull.wait;
buffer(in):=nextp;
in:=(in+1)mod n;
count:=count+1;
ifnotempty.queue then notempty.signal;
end
procedure entry get(item)
begin
if count<=0 then notempty.wait;
nextc:=buffer(out);
out:=(out+1)mod n;
count:=count-1;
ifnotfull.queue then notfull.signal;
end
(2):利用管程解决生产者与消费者问题是,可以描述为:
producer: begin
repeat
producean item in nextp;
PC.put(item);
utilfalse;
end
consumer:begin
repeat
PC.get(item);
Consumer the item in nextc;
util false;
end
- 生产者与消费者得问题描述
- 生产者与消费者问题
- 生产者与消费者问题
- 生产者与消费者问题
- 生产者与消费者问题
- 生产者与消费者问题
- 生产者与消费者问题
- 生产者与消费者问题
- 消费者与生产者问题
- 生产者与消费者问题
- 生产者与消费者问题
- 消费者与生产者问题
- 生产者与消费者问题
- 生产者与消费者问题
- 生产者与消费者问题
- 生产者与消费者问题
- c语言描述生产者消费者问题
- 多线程_生产者消费者问题描述图
- AStar 算法(erlang版本)
- 修改Windows路由表
- Storm:多并行度下Spout和Blot实体间Tuple的定向传输(tuple在多流时的路由)
- PL/SQL:ORA-00980同义词转换不再有效
- Android-JNI开发总结
- 生产者与消费者得问题描述
- 语言模型
- C/C++不同文件夹下包含头文件的方法及#include的使用
- 博社村民用新康泰克制毒 小学生剥壳倒粉末月入1万
- java学习——类的继承(2)
- Hadoop集群监测工具——ganglia安装实例
- 推荐13款JavaScript图形和图表绘制工具
- 姬松茸1
- html-keycode码大全