aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/control/concurrency/semaphore.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/library/lux/control/concurrency/semaphore.lux')
-rw-r--r--stdlib/source/library/lux/control/concurrency/semaphore.lux8
1 files changed, 8 insertions, 0 deletions
diff --git a/stdlib/source/library/lux/control/concurrency/semaphore.lux b/stdlib/source/library/lux/control/concurrency/semaphore.lux
index 597e96306..821250fb3 100644
--- a/stdlib/source/library/lux/control/concurrency/semaphore.lux
+++ b/stdlib/source/library/lux/control/concurrency/semaphore.lux
@@ -46,6 +46,8 @@
#waiting_list queue.empty}))))
(def: #export (wait semaphore)
+ {#.doc (doc "Wait on a semaphore until there are open positions."
+ "After finishing your work, you must 'signal' to the semaphore that you're done.")}
(Ex [k] (-> Semaphore (Promise Any)))
(let [semaphore (:representation semaphore)
[signal sink] (: [(Promise Any) (Resolver Any)]
@@ -70,6 +72,7 @@
["Max Positions" (%.nat max_positions)]))
(def: #export (signal semaphore)
+ {#.doc (doc "Signal to a semaphore that you're done with your work, and that there is a new open position.")}
(Ex [k] (-> Semaphore (Promise (Try Int))))
(let [semaphore (:representation semaphore)]
(promise.future
@@ -100,6 +103,7 @@
{#.doc "A mutual-exclusion lock that can only be acquired by one process at a time."}
(def: #export (mutex _)
+ {#.doc (doc "Creates a brand-new mutex.")}
(-> Any Mutex)
(:abstraction (semaphore 1)))
@@ -112,6 +116,7 @@
(|>> :representation ..signal))
(def: #export (synchronize mutex procedure)
+ {#.doc (doc "Runs the procedure with exclusive control of the mutex.")}
(All [a] (-> Mutex (IO (Promise a)) (Promise a)))
(do promise.monad
[_ (..acquire mutex)
@@ -121,9 +126,11 @@
)
(def: #export limit
+ {#.doc (doc "Produce a limit for a barrier.")}
(refinement.refinement (n.> 0)))
(type: #export Limit
+ {#.doc (doc "A limit for barriers.")}
(:~ (refinement.type limit)))
(abstract: #export Barrier
@@ -167,6 +174,7 @@
)
(def: #export (block barrier)
+ {#.doc (doc "Wait on a barrier until all processes have arrived and met the barrier's limit.")}
(-> Barrier (Promise Any))
(do promise.monad
[_ (..start barrier)]