Just another Perl shrine | |
PerlMonks |
Re: Multi-thread friendly object life-time handling for XS modulesby syphilis (Archbishop) |
on Nov 06, 2017 at 12:54 UTC ( [id://1202838]=note: print w/replies, xml ) | Need Help?? |
So, my question is, what mechanism could be used to avoid that This is quite possibly a non-helpful response, but I think that "blessing" the new SV into package NULL is one way of avoiding the issue. This effectively means that when the SV goes out of scope, it gets garbage-collected, but the object it points to survives (because DESTROY wasn't called). Therefore, any other SV's that point to the same object are still valid. This also effectively means that the programmer has to take charge of determining if/when these objects are DESTROY()ed - or run the risk of memory leaks. For some reason that I've never understood, I provided in Math::MPFR the capability of creating such unblessed objects and it does seem to me to provide a way of avoiding the problem. With an object blessed into package Math::MPFR: With the unblessed object: Maybe that's an overly simplistic and/or irrelevant demo. (My knowledge of threads is very week.) Cheers, Rob
In Section
Seekers of Perl Wisdom
|
|