Advertisement
Guest User

Untitled

a guest
Jul 12th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. program FILO4;
  2.  
  3. var p: array [0..4] of semaphore;
  4.    
  5.     k : integer;
  6.  
  7. process type filosofopar (i:integer);
  8. begin
  9.     repeat
  10.     {piensa }
  11.     writeln('filosofo ',i,' piensa');
  12.     wait(p[(i+1) mod 5]);
  13.     wait(p[i]);
  14.     {come}
  15.     writeln('filosofo ',i,' come');
  16.     signal(p[i]);
  17.     signal(p[(i+1) mod 5]);
  18.     writeln('filosofo ',i,' piensa');
  19.     Sleep(random(3));
  20.     forever
  21. end;
  22.  
  23. process type filosofoimpar (i:integer);
  24. begin
  25.     repeat
  26.     {piensa }
  27.     writeln('filosofo ',i,' piensa');
  28.     wait(p[(i+1) mod 5]);
  29.     wait(p[i]);
  30.     {come}
  31.     writeln('filosofo ',i,' come');
  32.     signal(p[i]);
  33.     signal(p[(i+1) mod 5]);
  34.     writeln('filosofo ',i,' piensa');
  35.     Sleep(random(3));
  36.     forever
  37. end;
  38.  
  39.  
  40. var Filopar: array [0..4] of filosofopar;
  41. var Filoimpar: array [0..4] of filosofoimpar;
  42.  
  43. begin      
  44.         for k:=0 to 4 do
  45.         begin
  46.             initial(p[k],1);
  47.         end;
  48.         cobegin
  49.         for k:=0 to 4 do
  50.         begin
  51.             if k mod 2 = 0 then
  52.             begin
  53.                 Filopar[k](k);
  54.             end
  55.             else
  56.                 begin
  57.                 Filoimpar[k](k);
  58.                 end
  59.         end;
  60.         coend;
  61.  
  62. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement