The __rw_setlocale destructor currently restores the previous locale when it
isn't holding the lock. This can cause problems if another thread takes the
lock and calls setlocale before the original thread restores the locale.
I believe this problem to be the cause of the following failure that I
frequently get when running the 22.locale.numpunct.mt test.
terminate called after throwing an instance of 'std::runtime_error'
what(): /amd/devco/vitek/stdcxx-trunk/src/setlocale.cpp:128:
__rw::__rw_setlocale::__rw_setlocale(const char *, int, int): bad locale name:
"À¡G.utf8"
Aborted (core dumped)
Note: The only time that the destructor needs to restore the locale is when the
locale was actually changed. That case is indicated when _C_guard is set to
some non-zero value.
Travis
2007-09-28 Travis Vitek <[EMAIL PROTECTED]>
* setlocale.cpp (~__rw_setlocale): Restore the previous
locale in a threadsafe manner. Simplified.
Index: setlocale.cpp
===================================================================
--- setlocale.cpp (revision 578875)
+++ setlocale.cpp (working copy)
@@ -135,18 +135,18 @@
// was in effect when the object was constructed
__rw_setlocale::~__rw_setlocale ()
{
- // release the lock
- if (_C_guard)
- __rw_setlocale_mutex._C_release ();
+ // if guard is set, constructor changed the locale
+ if (_C_guard) {
- if (_C_name) {
-
- // and restore the locale
+ // restore the locale
::setlocale (_C_cat, _C_name);
- if (_C_name != _C_namebuf)
- delete [] _C_name;
+ // release the lock
+ __rw_setlocale_mutex._C_release ();
}
+
+ if (_C_name != _C_namebuf)
+ delete [] _C_name;
}