[PATCH] Don't use ManagedStatic.

Reid Kleckner rnk at google.com
Mon Jun 8 20:03:53 PDT 2015


On Mon, Jun 8, 2015 at 9:05 AM, Rui Ueyama <ruiu at google.com> wrote:

> Looks like C++11 guarantees that the following pattern is thread-safe. So
> we can do just like this?
>
> static Foo &getSingleton() {
>   static Foo x;
>   return x;
> }
>

The major limitations with MSVC are:
- Despite the C++11 rules, static local variables are not thread safe in VS
2013, which is the recommended MSVC version.
- 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.

The thing that does work is using the Win32 API directly.

Another thing that doesn't work is hand-rolling double checked locking
yourself with std::atomic because std::atomic isn't trivially constructible
(oops).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150608/482a98fa/attachment.html>


More information about the llvm-commits mailing list