12345678910111213141516171819202122232425262728293031323334 |
- define Nproc 4
- P ==
- [
- i = 1 ->
- sem!init(1)
- []
- i /= 1 -> skip
- ];
- *[ true ->
- sem!P ();
- print ("ressource : " + ressource + "\n");
- ressource := ressource + i;
- sleep(10000);
- sem!V ()
- ]
- SEMAPHORE ==
- val : integer := 0;
- *[
- (i:1..Nproc) proc[i]?V() -> val := val+1 /*print("(" + val + ")" + "\n")*/
- []
- (i:1..Nproc) val >0; proc[i]?P () -> val := val -1
- []
- (i:1..Nproc) proc[i]?init (val) -> skip
- ]
- MAIN ==
- ressource : integer := 0;
- [
- proc [i:1..Nproc] :: P
- ||
- sem :: SEMAPHORE
- ]
|