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

Re: dealing with objects cloning under ithreads

Thread Previous | Thread Next
Elizabeth Mattijsen
November 15, 2003 08:14
Re: dealing with objects cloning under ithreads
Message ID:
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


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