Making semaphore work