Re: [Boost-bugs] [Boost C++ Libraries] #2854: Boost assertion fails inconsistently

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #2854: Boost assertion fails inconsistently
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-03-16 11:53:43


#2854: Boost assertion fails inconsistently
----------------------------------------+-----------------------------------
  Reporter: dineshkherajani_at_[hidden] | Owner: johnmaddock
      Type: Bugs | Status: closed
 Milestone: Boost 1.39.0 | Component: regex
   Version: Boost 1.35.0 | Severity: Problem
Resolution: invalid | Keywords:
----------------------------------------+-----------------------------------
Changes (by johnmaddock):

  * status: new => closed
  * resolution: => invalid

Comment:

 Hi Dinesh,

 there is a race condition in your parseURL function: if two threads enter
 the function at the same time and the variable e has not yet been
 initialised then one thread will start initialising the variable, but the
 other thread may then access it before initialisation is complete.

 There are two possible workarounds:

 1) Make the regular expression a static data member of the URL class - it
 will then get initialised at program startup. This is then thread safe
 provided no threads call URL::parseURL before the start of main(). One
 other downside is that the regex variable will get initialised whether it
 is used or not: that's not a problem in this one case, but may be if you
 have a *lot* of such variables.

 2) Use boost::call_once to call an initialisation function function that
 initialises the regex: this isn't cost free either as call_once has a non-
 zero overhead.

 I'm going to close this issue down for now, but please reopen if you find
 more problems (or this isn't the solution), or if you need the call_once
 method explaining in more detail.

 Regards, John Maddock.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/2854#comment:3>
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:49:59 UTC