Return-Path: X-Original-To: apmail-stdcxx-dev-archive@www.apache.org Delivered-To: apmail-stdcxx-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3AD90D654 for ; Wed, 5 Sep 2012 18:39:57 +0000 (UTC) Received: (qmail 33817 invoked by uid 500); 5 Sep 2012 18:39:57 -0000 Delivered-To: apmail-stdcxx-dev-archive@stdcxx.apache.org Received: (qmail 33771 invoked by uid 500); 5 Sep 2012 18:39:57 -0000 Mailing-List: contact dev-help@stdcxx.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@stdcxx.apache.org Delivered-To: mailing list dev@stdcxx.apache.org Received: (qmail 33760 invoked by uid 99); 5 Sep 2012 18:39:57 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 05 Sep 2012 18:39:57 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [64.34.174.152] (HELO hates.ms) (64.34.174.152) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 05 Sep 2012 18:39:48 +0000 Received: from [192.168.72.105] (unknown [166.57.38.196]) by hates.ms (Postfix) with ESMTPSA id DF1D845C180 for ; Wed, 5 Sep 2012 18:39:26 +0000 (UTC) Message-ID: <50479CA6.8010306@hates.ms> Date: Wed, 05 Sep 2012 14:40:38 -0400 From: Liviu Nicoara User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:15.0) Gecko/20120824 Thunderbird/15.0 MIME-Version: 1.0 To: dev@stdcxx.apache.org Subject: Re: STDCXX-1056 [was: Re: STDCXX forks] References: <40394653-8FCC-4D04-A108-2C650AF8F95B@hates.ms> <5045E764.9090607@hates.ms> <595887D2-6E42-4BC4-AF69-085AE4BA8A7D@hates.ms> <5046BDC1.3020400@gmail.com> <50476748.9040301@gmail.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 09/05/12 14:09, Stefan Teleman wrote: > On Wed, Sep 5, 2012 at 10:52 AM, Martin Sebor wrote: > [...] > OK so I did a little bit of testing, after looking at the *right* > __rw_guard class. :-) > > I changed the std::numpunct class thusly: > [...] > And then: > > template > inline string numpunct<_CharT>::grouping () const > { > if (!(_C_flags & _RW::__rw_gr)) { > > _RWSTD_MT_GUARD (_C_object_mutex); > > // double-test here to avoid re-writing an already written string > if (!(_C_flags & _RW::__rw_gr)) { > > numpunct* const __self = _RWSTD_CONST_CAST (numpunct*, this); > > // [try to] get the grouping first (may throw) > // then set a flag to avoid future initializations > __self->_C_grouping = do_grouping (); > __self->_C_flags |= _RW::__rw_gr; > > } > } > > return _C_grouping; > } I am afraid this would be unsafe, too (if I said otherwise earlier I was wrong). The compiler might re-arrange the protected assignments, such that another thread sees a partially updated object, where the flags are updated and the string not. I don't think we're going to get away with this here without either a simpler and more inefficient top-level locking, or doing away completely with the lazy initialization. Thoughts? Liviu