Added down-up processing to semaphore