<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Jun 8, 2015 at 9:05 AM, Rui Ueyama <span dir="ltr"><<a href="mailto:ruiu@google.com" target="_blank">ruiu@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Looks like C++11 guarantees that the following pattern is thread-safe. So we can do just like this?<div><br></div><div>static Foo &getSingleton() {</div><div>  static Foo x;</div><div>  return x;<br>}</div></div></blockquote><div><br></div><div>The major limitations with MSVC are:</div><div>- Despite the C++11 rules, static local variables are not thread safe in VS 2013, which is the recommended MSVC version.</div><div>- Last time we tried call_once, we found that MSVC's implementation of std::call_once doesn't work until main() starts due, you guessed it, static initializers.</div><div><br></div><div>The thing that does work is using the Win32 API directly.</div><div><br></div><div>Another thing that doesn't work is hand-rolling double checked locking yourself with std::atomic because std::atomic isn't trivially constructible (oops).</div></div></div></div>