Fix garbage collection of shared data. #1348

This commit is contained in:
Alessandro Ranellucci 2013-07-23 23:18:22 +02:00
parent 9d13a90837
commit aa2ad3bbd2

View File

@ -86,7 +86,12 @@ sub parallelize {
my $q = Thread::Queue->new; my $q = Thread::Queue->new;
$q->enqueue(@items, (map undef, 1..$Config->threads)); $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) { foreach my $th (map threads->create($thread_cb), 1..$Config->threads) {
$params{collect_cb}->($th->join); $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 { sub encode_path {
my ($filename) = @_; my ($filename) = @_;
return encode('locale_fs', $filename); return encode('locale_fs', $filename);