From 3465addf386e153410644616b45ed870a4098a3d Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 16 Jun 2014 18:40:55 +0200 Subject: algorithms MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- info/cmdipc.texinfo | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) diff --git a/info/cmdipc.texinfo b/info/cmdipc.texinfo index 73f03ee..0d2271b 100644 --- a/info/cmdipc.texinfo +++ b/info/cmdipc.texinfo @@ -412,6 +412,20 @@ To enter a guarded state with a mutex, use the verb @option{enter}. Then leave it with @option{leave}. +@* +@cartouche +@example +create: + s := S(1) + +enter: + P(s) + +leave: + V(s) +@end example +@end cartouche + @node Conditions @@ -462,6 +476,34 @@ command line arguments) perform a @option{broadcast} if there are any waiting peers, and otherwise @option{wait}. +@* +@cartouche +@example +create: + (s, c, q) := (S(1), S(0), S(0)) + +enter: + P(s) + +leave: + V(s) + +wait: + V(s), V(c), P(q), P(c), P(s) + +notify: + V(q) + +broadcast: + c.value times: + V(q) + +notify all: + max(c.value, 1) times: + V(q) +@end example +@end cartouche + @node Barriers @@ -499,6 +541,33 @@ no NUL or slash, between 1 character and 254 characters long, and prefixed with a slash. +@* +@cartouche +@example +[sysv] create: + (s, m) := (S(threshold), S(1)) + +[sysv] enter: + P(s), Z(s) + if P(m, nonblocking) does not fail: + if s.value = 0: + s.value := threshold + V(m) + +[posix] create: + (x, c, q) := (S(1), S(0), S(0)) + +[posix] enter: + P(x), V(c) + if c.value = threshold: + V(q, delta = threshold - 1) + c.value := 0 + V(x) + else: + V(x), P(q) +@end example +@end cartouche + @node Shared Locks @@ -553,8 +622,34 @@ Release shared locking. @item exclusive unlock Release exclusive locking. +@* @end table +@cartouche +@example +create: + (x, s, m) := (S(1), S(0), S(1)) + +shared lock: + P(m) + if s.value = 0: + P(x) + V(s), V(m) + +exclusive lock: + P(x) + +shared unlock: + P(m), P(s) + if s.value = 0: + V(x) + V(m) + +exclusive unlock: + V(x) +@end example +@end cartouche + @node Rendezvous @@ -583,6 +678,39 @@ no NUL or slash, between 1 character and 254 characters long, and prefixed with a slash. +@* +@cartouche +@example +[sysv] create: + (m, i, q) := (S(1), S(0), M()) + +[sysv] enter: + P(m) + if i.value = 0: + V(i), V(m) + send(q, type = 1) + receive(q, type = 2) + else: + P(i), V(m) + receive(q, type = 1) + send(q, type = 2) + +[posix] create: + (m, i, p, q) := (S(1), S(0), S(0), M()) + +[posix] enter: + P(m) + if i.value = 0: + V(i), V(m) + send(q), P(p) + receive(q) + else: + P(i), V(m) + receive(q), V(p) + send(q) +@end example +@end cartouche + @node GNU Free Documentation License -- cgit v1.2.3-70-g09d2