<div dir="ltr"><div dir="ltr"><div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Mon, Oct 29, 2018 at 9:01 AM Justin Holewinski via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">
<div>3. The global constructor for "mutex_init_flag" runs, resetting the flag indicating the call has already been made</div></div></blockquote><div><br></div><div>How does that happen? In my version of MSVC, once_flag has a constexpr constructor, so it shouldn't use dynamic initialization.</div><div><br></div><div>It looks like STL wrote a post about this a while ago:</div><div><a href="https://blogs.msdn.microsoft.com/vcblog/2015/07/14/stl-fixes-in-vs-2015-part-2/">https://blogs.msdn.microsoft.com/vcblog/2015/07/14/stl-fixes-in-vs-2015-part-2/</a></div><div><br></div><div>He said:</div><div>"* once_flag’s constructor wasn’t marked as constexpr as required by the Standard (DevDiv#497946).  (Note that while it’s marked as constexpr in VS 2015 RTM, it’s affected by the compiler bug DevDiv#1134662 “constexpr constructors are emitting dynamic initializers”, which we’re planning to fix in 2015 Update 1.)"</div><div><br></div><div>I checked, and it looks like MSVC emits a dynamic initializer for std::once_flag globals even though they are marked constexpr. So, LLVM's code is correct, but there is an MSVC compiler bug. We should probably work around it, though.</div><div><br></div><div>I think these days we have thread-safe static locals (check that we don't disable them with the compiler flag, though, please), so your suggested fix sounds good to me.</div></div></div></div></div>