|
Boost Users : |
Subject: Re: [Boost-users] [thread] boost::call_once() optimization idea on Win32
From: Dave Abrahams (dave_at_[hidden])
Date: 2010-11-18 12:40:38
On Wed, Nov 17, 2010 at 11:13 PM, Gottlob Frege <gottlobfrege_at_[hidden]> wrote:
>> Any flaws with this approach?
>>
>
> Yes.
>
> Your thread will see flag correctly, but the "important data" being
> protected/initted by the once, might not bee seen correctly.
<snip nice long explanation>
Another way to say it is that you are essentially trying to do the
classic "double-checked locking" (DCL) pattern, which is well-known
not to work and you can find plenty of explanations for. In fact,
the BOOST_THREAD_ONCE* stuff is there to solve exactly that problem.
-- Dave Abrahams BoostPro Computing http://www.boostpro.com
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net