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

  1. program attempt1;
  2. var 
  3.   p1requests, p2requests: 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.       p1requests := true; (* announce intent to enter *)
  13.       while p2requests do
  14.     null;  (* busy wait if other process is in critical section *)
  15.       (* enter critical section *)
  16.       shared := shared + 1;
  17.       (* leave critical section *)
  18.       p1requests :=false  (* exit protocol *)
  19.       (* non-critical section *)
  20.     end
  21. end;  (* P1 *)
  22.  
  23. process P2;
  24. var
  25.   loop: integer;
  26. begin
  27.   for loop := 1 to 20 do
  28.     begin
  29.       p2requests := true; (* announce intent to enter *)
  30.       while p1requests do
  31.     null;  (* busy wait if other process is in critical section *)
  32.       (* enter critical section *)
  33.       shared := shared + 1;
  34.       (* leave critical section *)
  35.       p2requests :=false  (* exit protocol *)
  36.       (* non-critical section *)
  37.     end
  38. end;  (* P2 *)
  39.  
  40. begin
  41.   shared := 0;
  42.   cobegin
  43.     P1;
  44.     P2
  45.   coend;
  46.   writeln(shared)
  47. end.