fix semaphore bug