develooper Front page | perl.perl5.porters | Postings from November 2003

Re: dealing with objects cloning under ithreads

Thread Previous | Thread Next
Mike Pomraning
November 15, 2003 10:34
Re: dealing with objects cloning under ithreads
Message ID:
threads::shared::_refcnt offers an alternative to the Scalar::Util::weaken
approach (although objects must be share()d):

  my $xs_dtor = \&SharedXSObject::DESTROY;
  *SharedXSObject::DESTROY = sub {
    return unless @_ and threads::shared::_refcnt($_[0]) == 1;
    # okay -- this is really the last ref to the underlying object!

I use this for safe DESTROYment of XS-backed objects without any CLONE
bookkeeping -- not only to avoid double free()ing, but specifically to prevent
the premature invalidation/shutdown of the underlying system resources.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About