From 14b295bdb00305370ec0aaad7f4319bad55ad6e9 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 17 Jan 2018 09:40:27 +0300 Subject: Add workaround for data race in libstdc++'s ctype::narrow() --- build2/b.cxx | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'build2/b.cxx') diff --git a/build2/b.cxx b/build2/b.cxx index c7219f0..1106031 100644 --- a/build2/b.cxx +++ b/build2/b.cxx @@ -10,6 +10,10 @@ #include // getenv() _putenv()(_WIN32) +#ifdef __GLIBCXX__ +# include +#endif + #include #include // strcmp(), strchr() #include @@ -152,6 +156,22 @@ main (int argc, char* argv[]) } #endif +// A data race happens in the libstdc++ (as of GCC 7.2) implementation of the +// ctype::narrow() function (bug #77704). The issue is easily triggered +// by the testscript runner that indirectly (via regex) uses ctype 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& ct (use_facet> (locale ())); + + for (size_t i (0); i != 256; ++i) + ct.narrow (static_cast (i), '\0'); + } +#endif + try { // On POSIX ignore SIGPIPE which is signaled to a pipe-writing process if -- cgit v1.1