fixed a dead loop when n_threads==1