semaphore
result = semaphore(n)
Input: n · Output: result
What it is
Creates a counting semaphore with n (integer, must be non-negative) initial permits.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = semaphore(n) | n Semaphore, Mutex, or Channelnot documented yet | result Semaphore, Mutex, or Channel | Returns a Semaphore handle (type(s) == "semaphore"); cloning it shares the same counter, the same convention Mutex/Channel use. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
s = semaphore(2) # 2 permits available
print(semaphore_available(s)) # 2
semaphore_acquire(s) # take one
print(semaphore_available(s)) # 1
semaphore_release(s) # give it back
print(semaphore_available(s)) # 2
output
2 1 2
from concurrency
How it works
semaphore(n) — a counting semaphore with n initial permits, for bounding concurrent access to a limited shared resource across spawn/parallel for workers (a hardware port, a connection pool, or just an explicit concurrency cap).
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.