[PATCH] Don't use ManagedStatic.

Chris Bieneman cbieneman at apple.com
Mon Jun 15 11:12:13 PDT 2015


Sorry for the late reply.

Just to add some additional context here WRT MSVC and std::call_once.

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 (http://reviews.llvm.org/D5473 <http://reviews.llvm.org/D5473>).

Ultimately the Windows problem was that certain versions of their C++ runtime would hang if call_once was called by a static initializer (yay!).

It went through numerous iterations, the last of which was submitted r220932 (http://reviews.llvm.org/D5922 <http://reviews.llvm.org/D5922>). Unfortunately even that revision had problems on PPC64 and had to be reverted (relevant thread: http://lists.cs.uiuc.edu/pipermail/llvmdev/2014-November/078465.html <http://lists.cs.uiuc.edu/pipermail/llvmdev/2014-November/078465.html>).

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.

-Chris

> On Jun 8, 2015, at 8:03 PM, Reid Kleckner <rnk at google.com> wrote:
> 
> On Mon, Jun 8, 2015 at 9:05 AM, Rui Ueyama <ruiu at google.com <mailto: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).
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150615/2f854ced/attachment.html>


More information about the llvm-commits mailing list