Re: [Boost-bugs] [Boost C++ Libraries] #8730: Race condition in once_block.hpp

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #8730: Race condition in once_block.hpp
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-06-26 07:08:58


#8730: Race condition in once_block.hpp
-------------------------------+------------------------------------------
  Reporter: apolukhin | Owner: andysem
      Type: Bugs | Status: new
 Milestone: To Be Determined | Component: log
   Version: Boost 1.54.0 | Severity: Problem
Resolution: | Keywords: call_once atomics thread log
-------------------------------+------------------------------------------

Comment (by andysem):

 Replying to [comment:6 apolukhin]:
> Replying to [comment:5 andysem]:
> > No, it won't. Since it's POD, its initialization is performed during
 the static initialization stage, which happens before any dynamic
 initialization. See 3.6.2 [basic.start.init] in the standard.
>
> This is not correct for *local objects with static storage duration*,
 see 6.7 of C++03:
>
> So you can not have 100% guarantee for that.

 Ok, you have a point. But note that once_block_flag::uninitialized is 0
 and zero initialization for local static objects is still performed before
 any other initialization. Most compilers will simply ignore the
 initializer for this reason. But I guess, it can be just removed from the
 macro definition to avoid the confusion and guarantee the correct
 behavior.

> > Once blocks offer more convenient syntax and are more lightweight than
 boost::call_once. BTW, boost::call_once also uses static initialization of
 its once_flag to achieve thread safety.
>
> Please show me the line where it uses local object with static storage
 duration.

 I was referring to the once_flag usage in the user's code (as a function-
 local static). But I guess since it is not guaranteed to be initialized
 statically (e.g. if BOOST_ONCE_INIT is not equivalent to zero
 initialization or the compiler is not smart enough to initialize the flag
 statically), it cannot be used that way.

 To be honest, I have yet to see the compiler that does not perform static
 initialization for local static PODs, even with non-zero values.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/8730#comment:7>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:13 UTC