From 75e0b72f0e0bb3669abbaf3313cddbb4da50f764 Mon Sep 17 00:00:00 2001 From: Nick Battle Date: Mon, 30 Sep 2013 07:59:49 +0100 Subject: [PATCH] Correction for two successive stop calls --- .../vdmj/scheduler/ISchedulableThread.java | 2 +- .../vdmj/scheduler/InitThread.java | 2 +- .../vdmj/scheduler/SchedulablePoolThread.java | 21 +++++++++++++------ .../vdmj/statements/StopStatement.java | 6 ++++-- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/core/vdmj/src/main/java/org/overturetool/vdmj/scheduler/ISchedulableThread.java b/core/vdmj/src/main/java/org/overturetool/vdmj/scheduler/ISchedulableThread.java index 6200e87cad..e58682f407 100644 --- a/core/vdmj/src/main/java/org/overturetool/vdmj/scheduler/ISchedulableThread.java +++ b/core/vdmj/src/main/java/org/overturetool/vdmj/scheduler/ISchedulableThread.java @@ -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); diff --git a/core/vdmj/src/main/java/org/overturetool/vdmj/scheduler/InitThread.java b/core/vdmj/src/main/java/org/overturetool/vdmj/scheduler/InitThread.java index 12121d8028..c55b5db129 100644 --- a/core/vdmj/src/main/java/org/overturetool/vdmj/scheduler/InitThread.java +++ b/core/vdmj/src/main/java/org/overturetool/vdmj/scheduler/InitThread.java @@ -200,7 +200,7 @@ public void clearAlarm() throw new NotSupportedError(); } - public void stopThread() + public boolean stopThread() { throw new NotSupportedError(); } diff --git a/core/vdmj/src/main/java/org/overturetool/vdmj/scheduler/SchedulablePoolThread.java b/core/vdmj/src/main/java/org/overturetool/vdmj/scheduler/SchedulablePoolThread.java index 5384510026..93854cd2d8 100644 --- a/core/vdmj/src/main/java/org/overturetool/vdmj/scheduler/SchedulablePoolThread.java +++ b/core/vdmj/src/main/java/org/overturetool/vdmj/scheduler/SchedulablePoolThread.java @@ -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; } } diff --git a/core/vdmj/src/main/java/org/overturetool/vdmj/statements/StopStatement.java b/core/vdmj/src/main/java/org/overturetool/vdmj/statements/StopStatement.java index b7ba1dfe2e..1c5c0a6719 100644 --- a/core/vdmj/src/main/java/org/overturetool/vdmj/statements/StopStatement.java +++ b/core/vdmj/src/main/java/org/overturetool/vdmj/statements/StopStatement.java @@ -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++; + } } }