Deadlock Appeared!

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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.