https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77704

--- Comment #10 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Boris Kolpackov from comment #5)
> For anyone interested, here is the workaround we came up with:
> 
> // A data race happens in the libstdc++ (as of GCC 7.2) implementation of the
> // ctype<ctype>::narrow() function (bug #77704). The issue is easily
> triggered
> // by the testscript runner that indirectly (via regex) uses ctype<char>
> facet
> // of the global locale (and can potentially be triggered by other locale-
> // aware code). We work around this by pre-initializing the global locale
> // facet internal cache.
> //
> #ifdef _GLIBCXX_
>   {
>     const ctype<char>& ct (use_facet<ctype<char>> (locale ()));
> 
>     for (size_t i (0); i != 256; ++i)
>       ct.narrow (static_cast<char> (i), '\0');
>   }
> #endif

It would be better to call ct.narrow(0, 0, 0, 0) as that will populate the
_M_narrow array and also set the _M_narrow_ok flag. Otherwise you can still get
later races on the flag.

Reply via email to