Add precautions so that threads won't race to exit1() and get stuck there.