This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch/RFC] Re: [RFC] 12658_thread.cc randomly fails (on MP machines)


Paolo Carlini wrote:

Now, I'm tentatively suspecting everything related to the locale::locale(const char*) constructor.

Indeed, the attached rough proof-of-concept patch, works for me!


Now we have to explain in detail *why* and refine it...

Opinions?

Paolo.

//////////////
diff -urN libstdc++-v3-orig/src/localename.cc libstdc++-v3/src/localename.cc
--- libstdc++-v3-orig/src/localename.cc	2004-06-28 13:18:03.000000000 +0200
+++ libstdc++-v3/src/localename.cc	2004-07-13 14:18:20.833321645 +0200
@@ -29,6 +29,13 @@
 #include <clocale>
 #include <cstring>
 #include <locale>
+#include <bits/concurrence.h>
+
+namespace __gnu_internal
+{
+  // Mutex objects for locale initialization.
+  __glibcxx_mutex_define_initialized(locale_named_mutex);
+} // namespace __gnu_internal
 
 namespace std
 {
@@ -38,7 +45,9 @@
   {
     if (__s)
       {
-	_S_initialize(); 
+	_S_initialize();
+	__gnu_cxx::lock sentry(__gnu_internal::locale_named_mutex);
+
 	if (std::strcmp(__s, "C") == 0 || std::strcmp(__s, "POSIX") == 0)
 	  (_M_impl = _S_classic)->_M_add_reference();
 	else if (std::strcmp(__s, "") != 0)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]