<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Sorry for the late reply.<div class=""><br class=""></div><div class="">Just to add some additional context here WRT MSVC and std::call_once.</div><div class=""><br class=""></div><div class="">While working on static initializer cleanup late last year I proposed a patch (submitted r219638), which added a new llvm_call_once API which had attempts at platform safe implementation of std::call_once. The code review is here (<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_D5473&d=AwMFAg&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=8yCGECJVw-IpzaUGLj4G31VAuh90AZ6Gwio3IpPZkn8&s=wvLtoxnJbtj6653USqq8ajwFxe7PkeQWs6FEoBC6B6w&e=" class="">http://reviews.llvm.org/D5473</a>).</div><div class=""><br class=""></div><div class="">Ultimately the Windows problem was that certain versions of their C++ runtime would hang if call_once was called by a static initializer (yay!).</div><div class=""><br class=""></div><div class="">It went through numerous iterations, the last of which was submitted r220932 (<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_D5922&d=AwMFAg&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=8yCGECJVw-IpzaUGLj4G31VAuh90AZ6Gwio3IpPZkn8&s=F0PI7d5CERiLpqkT8MZ-kbSWr0a-sI17PdEzR4ht9J8&e=" class="">http://reviews.llvm.org/D5922</a>). Unfortunately even that revision had problems on PPC64 and had to be reverted (relevant thread: <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2014-November/078465.html" class="">http://lists.cs.uiuc.edu/pipermail/llvmdev/2014-November/078465.html</a>).</div><div class=""><br class=""></div><div class="">I had meant to take up that patch again at some point, but have put it off because (1) it seemed to be a lot of work for little gain and (2) hopefully someday std::call_once will just work.</div><div class=""><br class=""></div><div class="">-Chris</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jun 8, 2015, at 8:03 PM, Reid Kleckner <<a href="mailto:rnk@google.com" class="">rnk@google.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote">On Mon, Jun 8, 2015 at 9:05 AM, Rui Ueyama <span dir="ltr" class=""><<a href="mailto:ruiu@google.com" target="_blank" class="">ruiu@google.com</a>></span> wrote:<br class=""><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" class="">Looks like C++11 guarantees that the following pattern is thread-safe. So we can do just like this?<div class=""><br class=""></div><div class="">static Foo &getSingleton() {</div><div class=""> static Foo x;</div><div class=""> return x;<br class="">}</div></div></blockquote><div class=""><br class=""></div><div class="">The major limitations with MSVC are:</div><div class="">- Despite the C++11 rules, static local variables are not thread safe in VS 2013, which is the recommended MSVC version.</div><div class="">- 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 class=""><br class=""></div><div class="">The thing that does work is using the Win32 API directly.</div><div class=""><br class=""></div><div class="">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>
_______________________________________________<br class="">llvm-commits mailing list<br class=""><a href="mailto:llvm-commits@cs.uiuc.edu" class="">llvm-commits@cs.uiuc.edu</a><br class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits<br class=""></div></blockquote></div><br class=""></div></body></html>