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

Re: dealing with objects cloning under ithreads

Thread Previous | Thread Next
From:
Mike Pomraning
Date:
November 15, 2003 10:34
Subject:
Re: dealing with objects cloning under ithreads
Message ID:
Pine.LNX.4.58.0311150945310.17161@localhost.localdomain
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!
    &$xs_dtor;
  }

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.

-Mike

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