Added check to semaphore initialization.