[vtk-developers] Crashes after recent checkins

Berk Geveci berk.geveci at kitware.com
Mon Aug 26 15:55:43 EDT 2013


Just pushed a topic that I hope fixes the issue properly:

http://review.source.kitware.com/#/t/3176

I carefully looked into the Schwarz Counter idiom and decided to uses a
modification of it. The issue here is that vtkTimeStamp.h is included by
every subclass of vtkObject - thousands of .cxx files. This would have
cause the creation of lots of static objects; initializer as it is called in

initializer

which lots of unnecessary allocation, counter incrementing, decrementing
etc. Please review the topic and comment. Or e-mail comments.

Bill: if you get this before you are done, can you give it a try?

-berk




On Mon, Aug 26, 2013 at 3:02 PM, Berk Geveci <berk.geveci at kitware.com>wrote:

> A few lines above that comment says:
>
>   // Note that this would not normally be thread safe. However,
>   // VTK initializes static objects at load time, which in turn call
>   // this functions, which make this thread safe. If this behavior
>   // changes, this should also be fixed by converting it to a static
>   // class member which is initialized at load time.
>
> That code gets called for the first time at library load time, which by
> definition would have to be done in a single thread. I would normally move
> it directly into library load time by using a static but then I run into
> initialization order issues. Actually, I realized that I can guarantee that
> it would get called at library load time. A fix coming shortly.
>
> -berk
>
>
>
> On Mon, Aug 26, 2013 at 1:29 PM, Brad King <brad.king at kitware.com> wrote:
>
>> On 08/26/2013 12:05 PM, Berk Geveci wrote:
>> > Can you try this?
>>
>> From the patch:
>>
>> +  if (!vtkTimeStamp::GlobalTimeStamp)
>> +    {
>> +#if VTK_SIZEOF_VOID_P == 8
>> +    vtkTimeStamp::GlobalTimeStamp = new vtkAtomicInt64;
>>
>> This runtime initialization is not thread-safe, which IIUC
>> is the entire point of using an atomic integer.  We can
>> achieve proper static initialization and finalization using
>> the same Schwarz Counter idiom:
>>
>>  http://en.wikibooks.org/wiki/More_C++_Idioms/Nifty_Counter
>>
>> that we already use in several places.  It provides a way
>> to order things across translation units.
>>
>> -Brad
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20130826/ae149805/attachment.html>


More information about the vtk-developers mailing list