[llvm-dev] Issue with initialization order for ManagedStaticMutex
Reid Kleckner via llvm-dev
llvm-dev at lists.llvm.org
Mon Oct 29 10:54:55 PDT 2018
On Mon, Oct 29, 2018 at 9:01 AM Justin Holewinski via llvm-dev <
llvm-dev at lists.llvm.org> wrote:
> 3. The global constructor for "mutex_init_flag" runs, resetting the flag
> indicating the call has already been made
>
How does that happen? In my version of MSVC, once_flag has a constexpr
constructor, so it shouldn't use dynamic initialization.
It looks like STL wrote a post about this a while ago:
https://blogs.msdn.microsoft.com/vcblog/2015/07/14/stl-fixes-in-vs-2015-part-2/
He said:
"* 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.)"
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.
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20181029/ac276e39/attachment.html>
More information about the llvm-dev
mailing list