Use semaphore to sync processes.