用信号量机制实现两任务共享单缓冲区的同步算法
发布网友
发布时间:2022-03-30 01:21
我来回答
共2个回答
热心网友
时间:2022-03-30 02:51
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
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
参考资料:http://jinhuidong.blog.sohu.com/134359800.html
热心网友
时间:2022-03-30 04:09
这儿有答案
http://wenwen.soso.com/z/q97982873.htm
参考资料:http://wenwen.soso.com/z/q97982873.htm