[llvm-commits] [llvm] r118463 - /llvm/trunk/lib/System/DynamicLibrary.cpp

Chris Lattner clattner at apple.com
Wed Nov 17 18:38:24 PST 2010


On Nov 17, 2010, at 4:25 PM, Owen Anderson wrote:

>> On Nov 9, 2010, at 10:51 AM, Chris Lattner wrote:
>> 
>>> 
>>> On Nov 9, 2010, at 9:51 AM, Owen Anderson wrote:
>>> 
>>>> 
>>>> On Nov 8, 2010, at 10:07 PM, Chris Lattner wrote:
>>>> 
>>>>> 
>>>>> On Nov 8, 2010, at 4:36 PM, Owen Anderson wrote:
>>>>> 
>>>>>> Author: resistor
>>>>>> Date: Mon Nov  8 18:36:06 2010
>>>>>> New Revision: 118463
>>>>>> 
>>>>>> URL: http://llvm.org/viewvc/llvm-project?rev=118463&view=rev
>>>>>> Log:
>>>>>> Fix PR8441, a thread unsafe static variable in our dynamic library loading facilities.
>>>>> 
>>>>> Hi Owen,
>>>>> 
>>>>> Does SmartMutex<true> cause a static constructor?
>>>> 
>>>> Yes, as does sys::Mutex.  Unfortunately, we can't use ManagedStatic here because it would introduce a circular dependency (System --> Support --> System).  I feel like we tried to move ManagedStatic to System at some point in the past, and that it didn't work out, but I don't remember why.
>>> 
>>> Why not just depend on threadsafe statics to handle this?  Targets that don't support threadsafe statics aren't going to support threads anyway.
> 
> Threadsafe statics won't help here.  The mutex needs to be accessible from both LoadLibraryPermanently() and SearchForAddressOfSymbol(), and we can't rely on one of them before called before the other to perform the initialization.

static bool DoMyInit() {
  ...
}

static void EnsureInitialized() {
  static bool x = DoMyInit();
}

LoadLibraryPermanently() {
  EnsureInitialized();
  ...
}

SearchForAddressOfSymbol() {
  EnsureInitialized();
  ...
}


?

-Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20101117/4d681587/attachment.html>


More information about the llvm-commits mailing list