semaphore_acquire
semaphore_acquire(s)
Input: s · Output: no output
What it is
Blocks the calling thread until a permit is free on semaphore handle s, then takes it (decrementing the available count by one).
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
semaphore_acquire(s) | s —not documented yet | no output | — |
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
2 1 2
from concurrency
How it works
semaphore_acquire(s) — blocks until a permit is free, then takes it. Unlike the mutex_* family, there's no self-contained atomic operation to offer here (the work done while holding the permit is arbitrary Qu code between the acquire and release calls), so — with no RAII/finally in Qu — releasing on an error path is the caller's job: semaphore_acquire(s) try ...critical work... catch err semaphore_release(s) error(err.message) end semaphore_release(s)
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.