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-25 21:24:00


#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:4 apolukhin]:
> {{{
> static boost::log::once_block_flag flag_var = {
 boost::log::once_block_flag::uninitialized };
> }}}
>
> where `boost::log::once_block_flag` is a POD type.
> Note the `static` keyword usage. It means that it will be converted by
 compiler to something like this:
> {{{
> if (!is_once_block_flag_inited) { // Variable constructed with compiler
> new (flag_var)
 boost::log::once_block_flag(boost::log::once_block_flag::uninitialized);
> is_once_block_flag_inited = true;
> }
> }}}

 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.

> That's only top of the iceberg. There are some more problems in
 `once_block_sentry::executed()`.

 What problems in particular?

> What for is all the code inside once_block.cpp: you are using
 `boost::thread` but do not use `boost::call_once`? What is the reason?

 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.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/8730#comment:5>
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