Fix busy loop waiting in semaphore implementation.