Skip to content

Commit

Permalink
Correction for two successive stop calls
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbattle committed Sep 30, 2013
1 parent f166706 commit 75e0b72
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public interface ISchedulableThread

public abstract void suspendOthers();

public abstract void stopThread();
public abstract boolean stopThread();

public abstract void reschedule(Context ctxt, LexLocation location);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public void clearAlarm()
throw new NotSupportedError();
}

public void stopThread()
public boolean stopThread()
{
throw new NotSupportedError();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,14 +431,23 @@ public static void signalAll(Signal sig)
BasicSchedulableThread.signalAll(sig);
}

public synchronized void stopThread()
public synchronized boolean stopThread()
{
stopCalled = true;
timestep = Long.MAX_VALUE; // Don't take part in time step

if (Thread.currentThread() != this.getThread())
if (!stopCalled)
{
stopCalled = true;
timestep = Long.MAX_VALUE; // Don't take part in time step

if (Thread.currentThread() != this.getThread())
{
setState(RunState.RUNNABLE); // So that thread is rescheduled
}

return true;
}
else
{
setState(RunState.RUNNABLE); // So that thread is rescheduled
return false;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@ private void stop(ObjectValue target, Context ctxt) throws ValueException
{
if (th instanceof ObjectThread || th instanceof PeriodicThread)
{
th.stopThread(); // This may stop current thread at next reschedule
count++;
if (th.stopThread()) // This may stop current thread at next reschedule
{
count++;
}
}
}

Expand Down

0 comments on commit 75e0b72

Please sign in to comment.