Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program FILO4;
- var p: array [0..4] of semaphore;
- k : integer;
- process type filosofopar (i:integer);
- begin
- repeat
- {piensa }
- writeln('filosofo ',i,' piensa');
- wait(p[(i+1) mod 5]);
- wait(p[i]);
- {come}
- writeln('filosofo ',i,' come');
- signal(p[i]);
- signal(p[(i+1) mod 5]);
- writeln('filosofo ',i,' piensa');
- Sleep(random(3));
- forever
- end;
- process type filosofoimpar (i:integer);
- begin
- repeat
- {piensa }
- writeln('filosofo ',i,' piensa');
- wait(p[(i+1) mod 5]);
- wait(p[i]);
- {come}
- writeln('filosofo ',i,' come');
- signal(p[i]);
- signal(p[(i+1) mod 5]);
- writeln('filosofo ',i,' piensa');
- Sleep(random(3));
- forever
- end;
- var Filopar: array [0..4] of filosofopar;
- var Filoimpar: array [0..4] of filosofoimpar;
- begin
- for k:=0 to 4 do
- begin
- initial(p[k],1);
- end;
- cobegin
- for k:=0 to 4 do
- begin
- if k mod 2 = 0 then
- begin
- Filopar[k](k);
- end
- else
- begin
- Filoimpar[k](k);
- end
- end;
- coend;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement