|
variables:
|
|
and operations ( |
The operations are linked with the variables as follows :
|
|
|
|
process in queue [train on the line] | |||
|
|
|
(
|
||||
| [empty line, enter it and set signal on ''red''] | ||||||
|
|
queue is empty |
|
(
|
|||
| queue not empty |
|
activate a (waiting) process | ||||
| [let one stopped train enter the line, signal remains on ''red''] |
The result is unique (
|
A
B |
procedure test (integer value k);
if C[(k-1) mod 5] <> 2 and C[k] == 1
and C[(k+1) mod 5] <> 2
begin C[k] := 2, V(prisem[k]) end
end
Remark :
1: cycle begin think
2: P(mutex)
3: C[w] := 1; test(w)
4: V(mutex)
5: P(prisem[w]); eat
6: P(mutex)
7: C[w] := 0; test[(w+1) mod 5];
test[(w-1) mod 5]
8: V(mutex)
9: end
Explanation: