optimize pthread termination in the non-detached case