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