use of abs.backend.java.scheduling.SimpleTaskScheduler.SimpleSchedulerThread in project abstools by abstools.
the class GlobalScheduler method doNextScheduleStep.
public void doNextScheduleStep() {
if (isShutdown)
return;
int i = counter.incrementAndGet();
logger.finest("===" + i + ": Do next step...");
ScheduleAction next = null;
synchronized (this) {
if (nextStepWaitStack.size() > 0) {
SimpleLock l = nextStepWaitStack.remove(nextStepWaitStack.size() - 1);
logger.finest("===" + i + ": Ignored step, awaking thread ");
l.unlock();
return;
}
if (options.isEmpty()) {
List<SimpleSchedulerThread> activeThreads = runtime.getThreadManager().getAllCopyOf(SimpleSchedulerThread.class);
if (!activeThreads.isEmpty()) {
Set<Task<?>> suspendedTasks = new HashSet<>();
for (SimpleSchedulerThread st : activeThreads) {
Task<?> t = st.getExecutingTask().task;
if (t != null && !t.isFinished()) {
suspendedTasks.add(t);
}
}
// Need to filter out currentTask (that is finishing)
Thread tt = Thread.currentThread();
if (tt instanceof SimpleSchedulerThread) {
Task<?> currT = ((SimpleSchedulerThread) tt).getExecutingTask().task;
suspendedTasks.remove(currT);
}
if (!suspendedTasks.isEmpty()) {
ABSException ex = new ABSDeadlockException();
for (Task<?> t : suspendedTasks) {
t.setException(ex);
}
runtime.handleABSException(suspendedTasks.iterator().next(), ex);
return;
}
}
logger.info("No steps left. Program finished");
logger.info("Total number of global choices: " + totalNumChoices);
if (totalNumChoices == 0) {
logger.info("Program is deterministic!");
}
return;
}
totalNumChoices += options.numOptions() - 1;
logger.finest("===" + i + " Choose next action...");
next = strategy.choose(options);
logger.finest("===" + i + " Action " + next + " choosen");
options.removeOption(next);
logger.finest("===" + i + " Executing Action " + next);
}
if (isShutdown)
return;
int j = counter.intValue();
if (i != j)
logger.warning("#### Interleaving detected " + i + " != " + j);
next.execute();
logger.finest("===" + i + " Action " + next + " was executed.");
}
Aggregations