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

Subject: [Boost-bugs] [Boost C++ Libraries] #8730: Race condition in once_block.hpp
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-06-25 15:44:50


#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
 Keywords: call_once atomics thread log |
------------------------------------------+---------------------
 First of all, `once_block_flag` is not thread safe. `status` variable
 shall be an atomic variable there.

 Another issue is `static boost::log::once_block_flag flag_var`. When
 previous issue will be fixed and `once_block_flag` will become thread
 safe, keyword `static` will do bad things in C++03. Static variable
 `foo_type foo` inside method in C++03 is equal to:

 {{{
 // In global namespace
 bool is_foo_inited = false;
 char place_for_foo[sizeof(foo_type)];

 // in place where a static variable is used
 if (!is_foo_inited) {
     new (place_for_foo) foo_type(some parameters);
     is_foo_inited = true;
 }
 return reinterpret_cast<foo_type&>(*place_for_foo);
 }}}

 Beacuse `is_foo_inited` is not atomic and does not act as a spin-lock
 during initialization - race conditions are possible.

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