add semaphore to limit the size of task queue.