Add thread cleanup to avoid double destruction of shared XS data

xsdata-boost
Alessandro Ranellucci 2013-07-11 16:17:36 +02:00
parent 3037b42b47
commit 8d171a297e
2 changed files with 19 additions and 5 deletions

View File

@ -87,11 +87,9 @@ sub parallelize {
$q->enqueue(@items, (map undef, 1..$Config->threads));
my $thread_cb = sub {
# prevent destruction of shared objects
no warnings 'redefine';
*Slic3r::ExPolygon::XS::DESTROY = sub {};
return $params{thread_cb}->($q);
my $result = $params{thread_cb}->($q);
Slic3r::thread_cleanup();
return $result;
};
@_ = ();
@ -103,6 +101,19 @@ 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::ExPolygon::XS::DESTROY = sub {};
*Slic3r::Point::XS::DESTROY = sub {};
}
sub encode_path {
my ($filename) = @_;
return encode('locale_fs', $filename);

View File

@ -570,6 +570,7 @@ sub export_gcode {
});
},
);
Slic3r::thread_cleanup();
});
$self->statusbar->SetCancelCallback(sub {
$self->{export_thread}->kill('KILL')->join;
@ -744,6 +745,8 @@ sub make_thumbnail {
} else {
$self->on_thumbnail_made($obj_idx);
}
Slic3r::thread_cleanup() if $Slic3r::have_threads;
};
@_ = ();