procedure TProducer.Execute;
begin
repeat
if n=MAXN then self.Suspend
else begin
n:=n+1;
WriteLn(‘Produced one item! n=’,n);
if n=1 then cons.Resume;
end;
until false;
end;
procedure TConsumer.Execute;
begin
repeat
if n=0 then self.Suspend
else begin
n:=n-1;
WriteLn(‘Consumed one item! n=’,n);
if n=MAXN-1 then prod.Resume;
{ GetItem; ConsumeItem; }
end;
until false;
end;
运行一段时间之后,终于看见DeadLock了……
Old Blog Link: http://computer.mblogger.cn/henryhu/posts/61832.aspx