Add task end flag to notice main thread finish event.