fix semaphore usage