home *** CD-ROM | disk | FTP | other *** search
/ cs.rhul.ac.uk / www.cs.rhul.ac.uk.zip / www.cs.rhul.ac.uk / pub / CS375 / gardens2.pfc < prev    next >
Text File  |  1999-03-15  |  602b  |  48 lines

  1. program gardens2;
  2. (* 
  3. semaphore solution to Ornamental 
  4. Gardens problem
  5. *)
  6.  
  7. var 
  8.   count: integer;
  9.   mutex: semaphore;
  10.  
  11. process turnstile1;
  12. var 
  13.   loop: integer;
  14. begin
  15.   for loop := 1 to 20 do
  16.     begin
  17.     wait(mutex);
  18.     count := count + 1;
  19.     signal(mutex)
  20.     end
  21. end;  (* turnstile1 *)
  22.  
  23.  
  24. process turnstile2;
  25. var
  26.   loop: integer;
  27. begin
  28.   for loop := 1 to 20 do
  29.     begin
  30.     wait(mutex);
  31.     count := count + 1;
  32.     signal(mutex)
  33.     end
  34. end;  (* turnstile2 *)
  35.  
  36.  
  37.  
  38.  
  39. begin
  40.   count := 0;
  41.   initial(mutex,1);
  42.   cobegin
  43.     turnstile1;
  44.     turnstile2
  45.   coend;
  46.   writeln('Total admitted: ',count)
  47. end.
  48.