adjust semaphore wait to avoid deadlock