Think about Loose Coupling | |
PerlMonks |
code executed at end of a threadby dk (Chaplain) |
on Dec 04, 2009 at 12:27 UTC ( [id://811070]=perlquestion: print w/replies, xml ) | Need Help?? |
dk has asked for the wisdom of the Perl Monks concerning the following question:
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.
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.
Back to
Seekers of Perl Wisdom
|
|