Skip to content

Commit

Permalink
Fix ThreadNexter shutdown killing nexter thread already executing a d…
Browse files Browse the repository at this point in the history
…ifferent task

Signed-off-by: Charles Oliver Nutter <headius@headius.com>
jmalves authored and headius committed Dec 12, 2017
1 parent 719ef28 commit 3011d3d
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions core/src/main/java/org/jruby/RubyEnumerator.java
Original file line number Diff line number Diff line change
@@ -745,20 +745,28 @@ public synchronized void shutdown() {

// mark for death
die = true;
if (dissociateNexterThread(true)) doneObject = null;
}

private synchronized boolean dissociateNexterThread(boolean interrupt) {
Thread nexterThread = thread;

Thread myThread = thread;
if (myThread != null) {
if (DEBUG) System.out.println("clearing for shutdown");
if (nexterThread != null) {
if (DEBUG) System.out.println("dissociating nexter thread, interrupt: " + interrupt);

// we interrupt twice, to break out of iteration and
// (potentially) break out of final exchange
myThread.interrupt();
myThread.interrupt();
if (interrupt) {
// we interrupt twice, to break out of iteration and
// (potentially) break out of final exchange
nexterThread.interrupt();
nexterThread.interrupt();
}

// release references
thread = null;
doneObject = null;
return true;
}

return false;
}

@Override
@@ -910,9 +918,8 @@ public IRubyObject call(ThreadContext context, IRubyObject[] args, Block block)
if (!die) out.put(finalObject);
}
catch (InterruptedException ie) { /* ignore */ }
}
finally {
thread = null; // disassociate this Nexter with the thread running it
} finally {
dissociateNexterThread(false); // disassociate this Nexter with the thread running it
}
}
}

0 comments on commit 3011d3d

Please sign in to comment.