Implementing semaphore.