Improved the reliability of per-thread locale by unsetting it at the end