stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Sebor <se...@roguewave.com>
Subject Re: [PATCH] set id of user locale facets safely
Date Fri, 28 Sep 2007 22:46:45 GMT
Travis Vitek wrote:
> 
> The method for initializing the facet id is not currently thread safe.
> 
> If a thread enters __rw_facet_id::_C_init() and is preempted after
> checking _C_id, a second thread can do the same check, increment the
> static counter, assign the facet id, and then return. The preempted
> thread would increment the static counter again, assign a new value to
> the facet id.
> 
> This could cause has_facet, use_facet, or locale constructor to fail
> unexpectedly.

I'm fine with the patch but I'm curious if we have tests that fail
as result of this? The standard facets all have their own unique
unchanged ids that are assigned when the facet is constructed by
the library.

The _C_init() function is (should be) only called on user-defined
specializations of facets (such as ctype<UserChar> or PhoneFacet).
Initialization of such facets should, of course, be thread-safe
as well but I don't think we have tests that exercise it.

> 
> 
> 2007-09-28  Travis Vitek  <vitek@roguewave.com>
> 
> 	* facet.cpp (_C_init): initialize facet id in a threadsafe
> 	manner.
> 
> 
> 
> Index: facet.cpp
> ===================================================================
> --- facet.cpp	(revision 578875)
> +++ facet.cpp	(working copy)
> @@ -597,17 +597,15 @@
>  
>  _RWSTD_SIZE_T __rw_facet_id::_C_init () const
>  {
> +    _RWSTD_MT_STATIC_GUARD(_RW::__rw_facet_id);

This is missing a space before the paren.

Martin

Mime
View raw message