fix a semaphore bug