aboutsummaryrefslogtreecommitdiffstats
path: root/doc/protocol
blob: a8465815ad5978fddbdcd92fe002f27f720f9883 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
create:
	Select a filename.

	Create XSI semaphore array {S = 0, W = 0, X = 1, Q = 0 and N = 0}
	with random key. Store the semaphore array's key in decimal form
	on the first line in the selected file.

	Create XSI shared memory, with an allocation of 2048 bytes, with a
	random key. Store the shared memory's key in decimal form on the
	second line in the selected file.


broadcast:
	with P(X):
	  Z(W)
	  Write NUL-terminate message to shared memory
	  with V(N): -- (1)
	    Q := 0
	    Z(S)

	-- (1) may be omitted if semaphores are known that
	   P(·), Z(·), V(·) cannot create a race condition
	   with a processes running Z(·).


listen:
	with V(S):
	  forever:
	    V(Q)
	    Z(Q)
	    Read NUL-terminated message from shared memory
	    if breaking:
	      break
	    with V(W):
	      with P(S):
	        Z(S)
	        Z(N)


`V(a)` means that semaphore a is released.
`P(a)` means that semaphore a is acquired.
`Z(a)` means that the process waits for semaphore a to become 0.
`with P(a)` that `P(a)` is done before the entering the scope,
and `V(a)` is done when exiting the scope. It also means that
these actions [P(a) and V(a)] are undone when the process exits,
or if the call fails.
`with V(a)` that `V(a)` is like `with P(a)` that `P(a)` and
`V(a)` are exchanged.