semaphore_available
result = semaphore_available(s)
Input: s · Output: result
What it is
Non-blocking snapshot of how many permits are free right now on semaphore handle s.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = semaphore_available(s) | s —not documented yet | result — | Returns an integer — a diagnostic, not a guarantee, since it can change the instant after it's read. |
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_available(s) — non-blocking: how many permits are free right now (a diagnostic snapshot, not a guarantee — it can change the instant after you read it).
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.