Use semaphore to switch the task