convert to use for_each_thread