diff options
author | Alessandro Ranellucci <aar@cpan.org> | 2013-07-24 01:18:22 +0400 |
---|---|---|
committer | Alessandro Ranellucci <aar@cpan.org> | 2013-07-24 01:18:22 +0400 |
commit | aa2ad3bbd2f4533e869a5a756d06cd017d2b0ac7 (patch) | |
tree | fee0fcac115dbaf67f5b6f185d5f598026457882 /lib | |
parent | 9d13a90837a7b019ccda6847205a285a7cf73147 (diff) |
Fix garbage collection of shared data. #1348
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Slic3r.pm | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/Slic3r.pm b/lib/Slic3r.pm index a3761ac6b..aac355b36 100644 --- a/lib/Slic3r.pm +++ b/lib/Slic3r.pm @@ -86,7 +86,12 @@ sub parallelize { my $q = Thread::Queue->new; $q->enqueue(@items, (map undef, 1..$Config->threads)); - my $thread_cb = sub { $params{thread_cb}->($q) }; + my $thread_cb = sub { + my $result = $params{thread_cb}->($q); + Slic3r::thread_cleanup(); + return $result; + }; + @_ = (); foreach my $th (map threads->create($thread_cb), 1..$Config->threads) { $params{collect_cb}->($th->join); @@ -96,6 +101,18 @@ sub parallelize { } } +# call this at the very end of each thread (except the main one) +# so that it does not try to free existing objects. +# at that stage, existing objects are only those that we +# inherited at the thread creation (thus shared) and those +# that we are returning: destruction will be handled by the +# main thread in both cases. +sub thread_cleanup { + # prevent destruction of shared objects + no warnings 'redefine'; + *Slic3r::Object::XS::ZTable::DESTROY = sub {}; +} + sub encode_path { my ($filename) = @_; return encode('locale_fs', $filename); |