Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re: How to avoid extra DESTROY calls in multi-threaded program?by ivancho (Hermit) |
on Dec 21, 2006 at 18:23 UTC ( [id://591157]=note: print w/replies, xml ) | Need Help?? |
not a threads expert, but it looks to me like on Win32, sharing is acheved by cloning the object several times to pass to different threads.. so if you try:
you'll see that only the last DESTROY is from an object created by 'new'..
Try an inside-out approach: in 'new', register the created $self in a static hash( ie, and then in DESTROY first check that your object is an original : update: added a little code to show that registering must happen after the blessing update 2: to be perfectly safe, you probably want instead to have a private attribute which is your key in the static hash.. otherwise if your object gets reblessed, you're screwed - "$self" will change
In Section
Seekers of Perl Wisdom
|
|