Set the locale per-thread instead of globally when generating shaders. Add cross-compatible versions of newlocale, uselocale and freelocale. This commit fixes a rare race condition when generating shaders because setlocale is global.