From 84760b8d59f908aad8a262e270bc41a669c1954e Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 13 Dec 2014 00:01:24 +0100 Subject: [PATCH] Require a recent threads.pm version because of upstream bug 85140 potentially causing deadlocks when stopping running threads. #2394 https://rt.cpan.org/Ticket/Display.html?id=85140 --- Build.PL | 1 + lib/Slic3r.pm | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Build.PL b/Build.PL index fee51ef54..fc5b16211 100644 --- a/Build.PL +++ b/Build.PL @@ -22,6 +22,7 @@ my %prereqs = qw( Test::More 0 Thread::Semaphore 0 IO::Scalar 0 + threads 1.96 Time::HiRes 0 ); my %recommends = qw( diff --git a/lib/Slic3r.pm b/lib/Slic3r.pm index e2c2646ef..d4344963f 100644 --- a/lib/Slic3r.pm +++ b/lib/Slic3r.pm @@ -82,17 +82,21 @@ use constant EXTERNAL_INFILL_MARGIN => 3; use constant INSET_OVERLAP_TOLERANCE => 0.2; # keep track of threads we created -my @threads : shared = (); +my @threads = (); my $sema = Thread::Semaphore->new; my $paused = 0; sub spawn_thread { my ($cb) = @_; + my $parent_tid = threads->tid; + @_ = (); my $thread = threads->create(sub { + Slic3r::debugf "Starting thread %d (parent: %d)...\n", threads->tid, $parent_tid; local $SIG{'KILL'} = sub { - Slic3r::debugf "Exiting thread...\n"; + Slic3r::debugf "Exiting thread %d...\n", threads->tid; + kill_all_threads(); Slic3r::thread_cleanup(); threads->exit(); }; @@ -205,6 +209,7 @@ sub kill_all_threads { # detach any running thread created in the current one my @killed = (); foreach my $thread (get_running_threads()) { + Slic3r::debugf "Thread %d killing %d...\n", threads->tid, $thread->tid; $thread->kill('KILL'); push @killed, $thread; } @@ -212,7 +217,11 @@ sub kill_all_threads { # unlock semaphore before we block on wait # otherwise we'd get a deadlock if threads were paused resume_threads(); - $_->join for @killed; # block until threads are killed + foreach my $thread (@killed) { + Slic3r::debugf " Threads %d waiting for %d...\n", threads->tid, $thread->tid; + $thread->join; # block until threads are killed + Slic3r::debugf " Thread %d finished waiting for %d...\n", threads->tid, $thread->tid; + } @threads = (); }