<div dir="ltr">Hello David,<div><br></div><div>This seems to be the same problem, and I like your solution the best of all of the different ways people recommend solving it. Thanks for helping me on this.</div><div><br></div><div>-Richard Jones</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jul 13, 2016 at 3:37 PM, David Lawrence <span dir="ltr"><<a href="mailto:davidl@jlab.org" target="_blank">davidl@jlab.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word"><div><br></div><div>Hi Richard,</div><div><br></div><div>  I spoke with Paul since I know we ran into this some time ago and found a solution. Digging through</div><div>the github logs, here is where Paul implemented the solution we came up with:</div><div><br></div><div><div style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(175,173,36)"><span>commit 61500561a96d5cb8d471c18bdb38d911611f3da9</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco"><span>Author: Paul Mattione <<a href="mailto:pmatt@jlab.org" target="_blank">pmatt@jlab.org</a>></span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco"><span>Date:   Tue Mar 17 15:35:54 2015 +0000</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;min-height:14px"><span></span><br></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco"><span>    Make global static variables in DTranslationTable have function scope instead. Return these by reference from these container functions, and access only by these functions.</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco"><span>    This fixes the crash-at-end-of-program problem (double-free, corrupted-memory) mentioned in the rev 17681 hd_root commit. Remove abort() call from hd_root.</span></div></div><div><span><br></span></div><div><span>For example, at the top of <a href="http://dtranslationtable.cc" target="_blank">DTranslationTable.cc</a> there is this:</span></div><div><span><br></span></div><div><span><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span>// Use one translation table for all threads</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>pthread_mutex_t& DTranslationTable::Get_TT_Mutex(</span><span style="color:#bb2ca2">void</span><span>) </span><span style="color:#bb2ca2">const</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>{</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span><span style="white-space:pre-wrap">        </span></span><span style="color:#bb2ca2">static</span><span> pthread_mutex_t tt_mutex = PTHREAD_MUTEX_INITIALIZER;</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span><span style="white-space:pre-wrap"> </span></span><span style="color:#bb2ca2">return</span><span> tt_mutex;</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>}</span></div><div><span><br></span></div><div><span><br></span></div><div><span>Previously, the “</span>tt_mutex” variable was global so when a plugin that had been linked with</div><div>the TTAB library was attached (dlopen), it automatically linked this. When the plugin is </div><div>detached (dlclose) it was treated it like it went out of scope, deleting it. Then, the same thing </div><div>happened at program exit leading to a double-free leading to a crash.</div><div><br></div><div>By replacing the global with a static local variable inside a globally accessible method, one</div><div>avoids this. So, you will need to hunt down where in the code a global variable is being used</div><div>and wrap it inside a global getter method as is done above in order to avoid these crashes.</div><div><br></div><div>Regards,</div><div>-David</div></span></div><div><div class="h5"><div><br></div><div><br></div><br><div><blockquote type="cite"><div>On Jul 13, 2016, at 3:11 PM, Paul Mattione <<a href="mailto:pmatt@jlab.org" target="_blank">pmatt@jlab.org</a>> wrote:</div><br><div><div>It’s only #include’d in danarest.  So, this problem would apply to every single class that’s #include’d into a plugin (such as DChargedTrack), so it’s unavoidable.  <br><br> - Paul<br><br>On Jul 13, 2016, at 3:05 PM, Richard Jones <<a href="mailto:richard.t.jones@uconn.edu" target="_blank">richard.t.jones@uconn.edu</a>> wrote:<br><br><blockquote type="cite">Hello Dave,<br><br>I have run into a nasty problem with segfaults at program exit. This seems to be related to the appearance of duplicate instances of some classes (eg. DEventWriterREST) that are defined both in the plugin (danarest.so) and the static library that is linked into hd_root (libHDDM.a). What is your policy with regard to classes that are used both in the static library and in the base code? <br><br>BTW there is the related question of why the DEventWriterREST is duplicated in two places in the tree, once in the Utilitiles/plugins/danarest and once in the libraries/HDDM area.<br><br>-Richard Jones<br>_______________________________________________<br>Halld-offline mailing list<br><a href="mailto:Halld-offline@jlab.org" target="_blank">Halld-offline@jlab.org</a><br><a href="https://mailman.jlab.org/mailman/listinfo/halld-offline" target="_blank">https://mailman.jlab.org/mailman/listinfo/halld-offline</a><br></blockquote><br></div></div></blockquote></div><br></div></div></div></blockquote></div><br></div>