Hi Monks,

I have a problem which I can't resolve so far. The problem goes with that I have a module, that creates some objects for internal use, that are cleared up in END{} block, before the global destruction. Which makes sense, because if it doesn't do so, all kinds of strange errors appear because some scalar A expects a scalar B alive in DESTROY, but B was killed already by global destruction mechaism, etc... So far so good.

But, the very same module doesn't fare well as soon an unrelated code starts to use threads. When that thread ends, it also brings down all copied references from the parent thread, including the internal objects from the said module. But since END{} block is not executed by the end of a thread, global destruction kills these object without an order, and the problems described above reappear.

My question is, is there a mechanism, or a best practice of sorts, how to deal with such situations? I see following possibilities:

* Rewrite module with explicit init() and done() calls. Would solve the problem, but one of main ideas of that module was actually to be transparent and not to require any calls of such kind. Also, if a thread exits with threads->exit it wouldn't help.
* Submit a patch to perl that enables an ENDTHREAD {} or something like that. Possible, but requires a lenghty discussion and release process, and I need a solution now.

Anything I missed? All ideas are welcome. Thanks!

Update: perlfaq8 brings even more confusion with this sentence: 'Each package's END block is called when the program or thread ends'. Well, it doesn't now.


In reply to code executed at end of a thread by dk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.