Wrap semaphore.release() in a try/finally block.