home *** CD-ROM | disk | FTP | other *** search
/ cs.rhul.ac.uk / www.cs.rhul.ac.uk.zip / www.cs.rhul.ac.uk / pub / CS375 / attempt2.pc < prev    next >
Text File  |  1999-02-05  |  743b  |  47 lines

  1. program attempt2;
  2. var 
  3.   p1inside, p2inside: boolean;
  4.   shared: integer;
  5.  
  6. process P1;
  7. var
  8.   loop: integer;
  9. begin
  10.   for loop := 1 to 20 do
  11.     begin
  12.       while p2inside do
  13.     null;
  14.       p1inside := true;
  15.       (* enter critical section *)
  16.       shared := shared + 1;
  17.       (* leave critical section *)
  18.       p1inside := false
  19.     end
  20. end;  (* P1 *)
  21.  
  22. process P2;
  23. var
  24.   loop: integer;
  25. begin
  26.   for loop := 1 to 20 do
  27.     begin
  28.       while p1inside do
  29.     null;
  30.       p2inside := true;
  31.       (* enter critical section *)
  32.       shared := shared + 1;
  33.       (* leave critical section *)
  34.       p2inside := false
  35.     end
  36. end;  (* P2 *)
  37.  
  38. begin
  39.   p1inside := false;
  40.   p2inside := false;
  41.   shared := 0;
  42.   cobegin
  43.     P1;
  44.     P2
  45.   coend;
  46.   writeln(shared)
  47. end.