dk has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: code executed at end of a thread
by BrowserUk (Patriarch) on Dec 04, 2009 at 13:00 UTC | |
by dk (Chaplain) on Dec 04, 2009 at 21:38 UTC | |
|
Re: code executed at end of a thread
by zentara (Cardinal) on Dec 04, 2009 at 13:06 UTC | |
by dk (Chaplain) on Dec 04, 2009 at 14:59 UTC | |
by zentara (Cardinal) on Dec 04, 2009 at 18:22 UTC | |
by dk (Chaplain) on Dec 05, 2009 at 13:22 UTC |