Fix race in ThreadsManager::sleep()