[Boost-bugs] [Boost C++ Libraries] #3407: boost::call_once not re-entrant (at least in win32)

Subject: [Boost-bugs] [Boost C++ Libraries] #3407: boost::call_once not re-entrant (at least in win32)
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-09-06 03:07:02

#3407: boost::call_once not re-entrant (at least in win32)
 Reporter: Vincent Falco <thevinn@…> | Owner: anthonyw
     Type: Bugs | Status: new
Milestone: Boost 1.41.0 | Component: threads
  Version: Boost 1.40.0 | Severity: Problem
 Keywords: threads |
 The win32 implementation of boost::call_once ( boost/thread/win32/once.hpp
 version 1.40.0 ) is not reentrant for the same thread. The problem happens
 on line 127. The function is called, and then the flag is set. This order
 should be reversed, the flag should be set and then the function should be
 called. If the function throws, the flag must be set back.

 This program demonstrates the issue:

 #include <boost/thread/once.hpp>

 static boost::once_flag flag;

 void called_twice()
         boost::call_once( called_twice, flag );

         // gets here twice

 int main()
         boost::call_once( called_twice, flag );

 While this may seem like a contrived example, it can easily happen in
 practice. Consider the case of a boost::singleton constructor that calls a
 function which then accesses its 'instance' member. The result will be
 that the singleton is created twice, because call_once is not re-entrant.

 Also consider the case of two singletons, A and B. A calls methods on B
 from its constructor, and B calls methods on A from its constructor. A
 will be created twice due to the non-reentrant behavior of call_once.

 I have not studied the behavior of call_once for other platforms.

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