update thread_select to non-recursive version