Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In <a href="http://en.wikipedia.org/wiki/C++11" rel="noreferrer">C++11</a>, it is thread safe. According to the <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3337.pdf" rel="noreferrer">standard</a>, <code>§6.7 [stmt.dcl] p4</code>:</p> <blockquote> <p>If control enters the declaration concurrently while the variable is being initialized, the <strong>concurrent execution shall wait</strong> for completion of the initialization.</p> </blockquote> <p>GCC and VS support for the feature (<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2660.htm" rel="noreferrer">Dynamic Initialization and Destruction with Concurrency</a>, also known as <a href="https://msdn.microsoft.com/en-us/library/hh567368.aspx" rel="noreferrer">Magic Statics on MSDN</a>) is as follows:</p> <ul> <li>Visual Studio: supported since <a href="https://msdn.microsoft.com/en-us/library/hh567368(v=vs.140).aspx" rel="noreferrer">Visual Studio 2015</a></li> <li>GCC: supported since <a href="https://gcc.gnu.org/gcc-4.3/changes.html" rel="noreferrer">GCC 4.3</a></li> </ul> <p>Thanks to @Mankarse and @olen_gam for their comments.</p> <hr /> <p>In <a href="http://en.wikipedia.org/wiki/C++03" rel="noreferrer">C++03</a>, this code wasn't thread safe. There is an article by Meyers called <a href="http://www.aristeia.com/Papers/DDJ_Jul_Aug_2004_revised.pdf" rel="noreferrer">"C++ and the Perils of Double-Checked Locking"</a> which discusses thread safe implementations of the pattern, and the conclusion is, more or less, that (in C++03) full locking around the instantiating method is basically the simplest way to ensure proper concurrency on all platforms, while most forms of double-checked locking pattern variants may suffer from <a href="https://stackoverflow.com/a/6623662/69809">race conditions on certain architectures</a>, unless instructions are interleaved with strategically places memory barriers.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload