Last active
December 19, 2015 00:39
-
-
Save tonussi/5870628 to your computer and use it in GitHub Desktop.
nadadores
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| program piscina; | |
| var st: array[1..14] of char; | |
| monitor cesto; | |
| export pega, larga; | |
| var ncesto: integer; | |
| ccesto: condition; | |
| procedure pega; | |
| begin | |
| if (ncesto = 0) then | |
| delay (ccesto); | |
| ncesto := ncesto - 1; | |
| end; | |
| procedure larga; | |
| begin | |
| ncesto := ncesto + 1; | |
| resume (ccesto); | |
| end; | |
| begin | |
| ncesto := 5; | |
| end; (*monitor cesto*) | |
| monitor cabine; | |
| export pega, larga; | |
| var ncabine: integer; | |
| ccabine: condition; | |
| procedure pega; | |
| begin | |
| if (ncabine = 0) then delay (ccabine); | |
| ncabine := ncabine - 1; | |
| end; | |
| procedure larga; | |
| begin | |
| ncabine := ncabine + 1; | |
| resume (ccabine); | |
| end; | |
| begin | |
| ncabine := 2; | |
| end; (*monitor cabine*) | |
| monitor interface; | |
| export alterast; | |
| var i: integer; | |
| procedure alterast ( nid: integer; est : char); | |
| var i : integer; | |
| begin | |
| st[nid] := est; | |
| for i := 1 to 14 do write (' ',st[i]); | |
| writeln; writeln; | |
| END; | |
| begin | |
| end; (*interface*) | |
| process type tpnadador ( nid : integer ); | |
| begin | |
| repeat | |
| interface.alterast( nid, 'A'); | |
| sleep( random ( 10 ) + 2 ); | |
| cesto.pega; | |
| cabine.pega; | |
| interface.alterast ( nid,'D'); | |
| sleep( random ( 8 ) + 2 ); | |
| cabine.larga; | |
| interface.alterast ( nid,'N'); | |
| cabine.larga; | |
| interface.alterast ( nid,'N'); | |
| sleep( random ( 10 ) + 5 ); | |
| cabine.pega; | |
| interface.alterast ( nid,'V'); | |
| sleep( random ( 8 ) + 2 ); | |
| cesto.larga; | |
| cabine.larga | |
| forever; | |
| end; (* tpnadador *) | |
| var nadador: array[1..14] of tpnadador; | |
| i: integer; | |
| begin | |
| cobegin | |
| for i:= 1 to 14 do nadador[i](i); | |
| coend; | |
| end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment