fix bug in semaphore