At 10:00 -0600 11/15/03, Mike Pomraning wrote: >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. Very interesting. I guess the question is: can threads::shared::_refcnt be considered part of the threads API? In any case, the problem is specific for unshared object really. Objects from modules that don't expect to have multiple DESTROY's called on their objects Liz!Thread Previous | Thread Next