develooper Front page | perl.ithreads | Postings from October 2003

Re: DESTROYing shared objects, finally

Thread Previous | Thread Next
From:
Mike Pomraning
Date:
October 29, 2003 22:01
Subject:
Re: DESTROYing shared objects, finally
Message ID:
Pine.LNX.4.58.0310292305160.4272@localhost.localdomain
On Thu, 23 Oct 2003, Mike Pomraning wrote:

> [....] suggestions on how I might determine which DESTROY [of a shared,
> blessed ref] is the very last one?

Sorry to reply to my own post, but here's how I've attempted to identify the
last DESTROY of a shared object:

  sub DESTROY {
    return unless threads::shared::_refcnt($_[0]) == 1;
    # if we're here, the shared object is going away for good.
    # time to release system resources, call XS deallocators, etc.
    }
  }

The only other approach I can think of is to do (ser|ted)ious inventorying via
CLONE, DESTROY and constructors, or a wrapped bless.  (I did see the
"[CAUTION] Thread-saving modules" not-a-bug thread from Jul 2002 before my
previous post, but this is not quite the same.)

Multiple destruction of non-shared objects makes sense to me, as each becomes
a thread-local copy.  Multiple destruction of shared objects, however, does
not (though I think I understand the mechanics of why it happens).  Am I
looking at this issue the wrong way?

Regards,
Mike
-- 
Michael J. Pomraning
mjp@pilcrow.madison.wi.us
http://pilcrow.madison.wi.us

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About