Skip to content

Commit

Permalink
Try harder to shut down Nexter thread.
Browse files Browse the repository at this point in the history
Don't look too close.
  • Loading branch information
headius committed May 8, 2013
1 parent 909a0d2 commit d3cf295
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/org/jruby/RubyEnumerator.java
Expand Up @@ -27,8 +27,8 @@
***** END LICENSE BLOCK *****/
package org.jruby;

import java.util.concurrent.Exchanger;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.locks.LockSupport;
import org.jruby.anno.JRubyMethod;
import org.jruby.anno.JRubyModule;
import org.jruby.runtime.Helpers;
Expand Down Expand Up @@ -554,7 +554,7 @@ private void checkIndex() throws RaiseException {
}

private static class ThreadedNexter extends Nexter implements Runnable {
private static final boolean DEBUG = false;
private static final boolean DEBUG = true;

/** sync queue to wait for values */
private SynchronousQueue<IRubyObject> out = new SynchronousQueue<IRubyObject>();
Expand Down Expand Up @@ -585,7 +585,19 @@ public synchronized IRubyObject next() {
public synchronized void shutdown() {
if (thread != null) {
if (DEBUG) System.out.println("clearing for shutdown");
// try to interrupt
thread.interrupt();
LockSupport.unpark(thread);
Thread.yield();

// try again
thread.interrupt();
LockSupport.unpark(thread);
Thread.yield();

// do the deed if it's still alive
if (thread.isAlive()) thread.stop(new ThreadDeath());

thread = null;
doneObject = null;
}
Expand Down

0 comments on commit d3cf295

Please sign in to comment.