Boldra has asked for the wisdom of the Perl Monks concerning the following question:
I have a problem cleaning the cache of Class::Std::Fast. Here's my test code, which dies while joining the threads:
My STR class has caching enabled, which means Class::Std::Fast doesn't really destroy instances of that class, it squirrels them away to be reused next time STR->new is called. This breaks when threads are joined anywhere in the program, even if no STR objects are in scope.package STR; use Class::Std::Fast cache => 1; ## ---------------- ---------------- ---------------- ## package main; use threads; use 5.010; use strict; use warnings; STR->new; # create and immediately throw away. # Now do something completely different with threads: threads->create( sub { sleep 2 && say "thread $_" } ) for 1..4; $_->join for threads->list;
What doesn't work:
- Calling ->DESTROY manually: The objects go out of scope anyway, see example above.
- Changing the import cache => 1. Caching really is desirable here.
- unloading Class::Std::Fast: My program needs to call 'CSF code -> threads -> CSF code' (although the CSF objects are completely different in the second call)
- Disabling caching in Class::Std::Fast::_cache_class_ref when I've finished using it.
Which means that just calling delete Class::Std::Fast::_cache_class_ref()->{STR} works beautifully, if I can only get around the croak!sub _cache_class_ref () { croak q{you can't call this method in your namespace} if 0 != index caller, 'Class::Std::'; return \%do_cache_class_of; }
Another avenue seems to be to dynamically override Class::Std::Fast::DESTROY, but doing this in a way that preserves all the original behaviour except caching would get very complex. Finding out if these behaviours even need to be preserved is even more complex.
Note: I'm not actually using Class::Std::Fast directly, I'm using SOAP::WSDL, which via 5 intermediate steps comes back to Class::Std::Fast. My real code is dying with
DESTROY created new reference to dead object 'SOAP::WSDL::XSD::Typelib::Builtin::string' during global dest +ruction (#1)
Does anyone have any suggestions?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Class::Std::Fast cache and threads
by Anonymous Monk on Oct 12, 2010 at 08:50 UTC | |
by Boldra (Deacon) on Oct 12, 2010 at 10:34 UTC | |
by BrowserUk (Patriarch) on Oct 12, 2010 at 10:44 UTC | |
by Boldra (Deacon) on Oct 12, 2010 at 11:22 UTC | |
by BrowserUk (Patriarch) on Oct 12, 2010 at 11:53 UTC | |
Re: Class::Std::Fast cache and threads
by Boldra (Deacon) on Oct 12, 2010 at 11:09 UTC | |
by BrowserUk (Patriarch) on Oct 12, 2010 at 14:21 UTC | |
by Boldra (Deacon) on Oct 13, 2010 at 15:35 UTC | |
by BrowserUk (Patriarch) on Oct 13, 2010 at 15:52 UTC |
Back to
Seekers of Perl Wisdom