1Stdlib.Semaphore(3) OCaml library Stdlib.Semaphore(3)
2
3
4
6 Stdlib.Semaphore - no description
7
9 Module Stdlib.Semaphore
10
12 Module Semaphore
13 : (module Stdlib__Semaphore)
14
15
16
17
18
19
20
21
22
23 Counting semaphores
24 A counting semaphore is a counter that can be accessed concurrently by
25 several threads. The typical use is to synchronize producers and con‐
26 sumers of a resource by counting how many units of the resource are
27 available.
28
29 The two basic operations on semaphores are:
30
31 -"release" (also called "V", "post", "up", and "signal"), which incre‐
32 ments the value of the counter. This corresponds to producing one more
33 unit of the shared resource and making it available to others.
34
35 -"acquire" (also called "P", "wait", "down", and "pend"), which waits
36 until the counter is greater than zero and decrements it. This corre‐
37 sponds to consuming one unit of the shared resource.
38
39
40 module Counting : sig end
41
42
43
44
45
46
47 Binary semaphores
48 Binary semaphores are a variant of counting semaphores where semaphores
49 can only take two values, 0 and 1.
50
51 A binary semaphore can be used to control access to a single shared re‐
52 source, with value 1 meaning "resource is available" and value 0 mean‐
53 ing "resource is unavailable".
54
55 The "release" operation of a binary semaphore sets its value to 1, and
56 "acquire" waits until the value is 1 and sets it to 0.
57
58 A binary semaphore can be used instead of a mutex (see module Mutex )
59 when the mutex discipline (of unlocking the mutex from the thread that
60 locked it) is too restrictive. The "acquire" operation corresponds to
61 locking the mutex, and the "release" operation to unlocking it, but
62 "release" can be performed in a thread different than the one that per‐
63 formed the "acquire". Likewise, it is safe to release a binary sema‐
64 phore that is already available.
65
66 module Binary : sig end
67
68
69
70
71
72
73
74OCamldoc 2023-07-20 Stdlib.Semaphore(3)