Boost logo

Boost Users :

Subject: Re: [Boost-users] [thread] safe portable static mutex initialization
From: Anthony Williams (anthony.ajw_at_[hidden])
Date: 2012-04-20 10:53:47


On 20/04/12 14:41, Dave Abrahams wrote:
> on Fri Apr 20 2012, Will Mason <willchido-AT-gmail.com> wrote:
>
>> On Fri, Apr 20, 2012 at 8:04 AM, Juan Ramírez <juanantonio.ram_at_[hidden]> wrote:
>> 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.

You are right: this is guaranteed in C++11.

Anthony

-- 
Author of C++ Concurrency in Action     http://www.stdthread.co.uk/book/
just::thread C++11 thread library             http://www.stdthread.co.uk
Just Software Solutions Ltd       http://www.justsoftwaresolutions.co.uk
15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976

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