implementing semaphores