Adding semaphore-counting

It is now possible to acquire more than one semaphore during the same
runtime.  This is done by counting semaphores and only actually acquiring
one when the count is incremented to 1 and releasing it when the count
is decremented to 0.