Handle race condition in creation of semaphore.