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:50:11
#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 apolukhin):
Replying to [comment:5 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.
This is not correct for *local objects with static storage duration*, see
6.7 of C++03:
A local object of POD type (3.9) with static storage duration initialized
with constant-expressions is initialized before its block is first
entered. An implementation is permitted to per-form early initialization
of other local objects with static storage duration under the same
conditions that an implementation is permitted to statically initialize an
object with static storage duration in namespace scope (3.6.2). Otherwise
such an object is initialized the first time control passes through its
declaration; such an object is considered initialized upon the completion
of its initialization.
So you can not have 100% guarantee for that.
> > That's only top of the iceberg. There are some more problems in
`once_block_sentry::executed()`.
>
> What problems in particular?
Did not noticed the `enter_once_block()` in it, so sorry - it is OK.
> > 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.
Please show me the line where it uses local object with static storage
duration.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/8730#comment:6> 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