QSem is a quantity semaphore in which the resource is acquired
and released in units of one. It provides guaranteed FIFO ordering
for satisfying blocked waitQSem calls.
withQSem is an exception-safe wrapper for performing the
provided operation while holding a unit of value from the semaphore.
It ensures the semaphore cannot be leaked if there are exceptions.