Fix garbage collection of shared data. #1348
This commit is contained in:
parent
9d13a90837
commit
aa2ad3bbd2
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user