Return-Path: Delivered-To: apmail-incubator-stdcxx-dev-archive@www.apache.org Received: (qmail 72420 invoked from network); 28 Sep 2007 23:27:03 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 28 Sep 2007 23:27:03 -0000 Received: (qmail 61487 invoked by uid 500); 28 Sep 2007 23:26:53 -0000 Delivered-To: apmail-incubator-stdcxx-dev-archive@incubator.apache.org Received: (qmail 61471 invoked by uid 500); 28 Sep 2007 23:26:53 -0000 Mailing-List: contact stdcxx-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: stdcxx-dev@incubator.apache.org Delivered-To: mailing list stdcxx-dev@incubator.apache.org Received: (qmail 61460 invoked by uid 99); 28 Sep 2007 23:26:53 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 Sep 2007 16:26:53 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [208.30.140.160] (HELO moroha.quovadx.com) (208.30.140.160) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 Sep 2007 23:26:54 +0000 Received: from qxvcexch01.ad.quovadx.com ([192.168.170.59]) by moroha.quovadx.com (8.13.6/8.13.6) with ESMTP id l8SNPsNB015023 for ; Fri, 28 Sep 2007 23:25:54 GMT X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Subject: [PATCH] __rw_setlocale not threadsafe Date: Fri, 28 Sep 2007 17:26:52 -0600 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [PATCH] __rw_setlocale not threadsafe Thread-Index: AcgCJwz7jDyEjfORRkyOD/MqbR28/g== From: "Travis Vitek" To: X-Virus-Checked: Checked by ClamAV on apache.org 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: "=C0=A1G.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 * setlocale.cpp (~__rw_setlocale): Restore the previous locale in a threadsafe manner. Simplified. Index: setlocale.cpp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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) { =20 - if (_C_name) { - - // and restore the locale + // restore the locale ::setlocale (_C_cat, _C_name); =20 - if (_C_name !=3D _C_namebuf) - delete [] _C_name; + // release the lock + __rw_setlocale_mutex._C_release (); } + + if (_C_name !=3D _C_namebuf) + delete [] _C_name; } =20 =20