cpp: fix potential deadlock in task_mgr