|
Boost Users : |
Subject: Re: [Boost-users] [thread] safe portable static mutex initialization
From: Dave Abrahams (dave_at_[hidden])
Date: 2012-04-20 09:41:43
on Fri Apr 20 2012, Will Mason <willchido-AT-gmail.com> wrote:
> Hello,
>
> On Fri, Apr 20, 2012 at 8:04 AM, Juan RamÃrez <juanantonio.ram_at_[hidden]> wrote:
>
> It's not related to the user type, neither to mutex initialization,
> it's related to variable initialization in general.
>
> A global static variable is guaranteed to be initialized before usage.
If you truly mean "static," such that it's not visible outside its
translation unit, that is correct.
> But the initialization of static variables declared inside a function
> is not guaranteed to be thread safe. So you could easily end up
> calling it's constructor twice.
>
> That's something that boost::call_once is good at preventing.
Correct, for C++03. I could be mis-remembering but IIRC in C++11
function-local static variables have been given automatic threadsafe
initialization.
-- 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