Each locale embeds a lazily initialized lconv which is populated by
localeconv(3) and localeconv_l(3). When setlocale(3) updates the global
locale, the lconv needs to be (lazily) reinitialized. To signal this,
we set flag variables in the locale structure. There are two problems:
- The flags are set before the locale is fully updated, so a concurrent localeconv() call can observe partially initialized locale data. - No barriers ensure that localeconv() observes a fully initialized locale if a flag is set.
So, move the flag update appropriately, and use acq/rel barriers to
provide some synchronization.
Thanks to Henry Hu <firstname.lastname@example.org> for providing a test case
demonstrating the race.
MFC after: 2 weeks