Search in sources :

Example 1 with ABSDeadlockException

use of abs.backend.java.lib.runtime.ABSDeadlockException 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.");
}
Also used : Task(abs.backend.java.lib.runtime.Task) ABSDeadlockException(abs.backend.java.lib.runtime.ABSDeadlockException) SimpleSchedulerThread(abs.backend.java.scheduling.SimpleTaskScheduler.SimpleSchedulerThread) HashSet(java.util.HashSet) SimpleSchedulerThread(abs.backend.java.scheduling.SimpleTaskScheduler.SimpleSchedulerThread) ABSException(abs.backend.java.lib.runtime.ABSException)

Aggregations

ABSDeadlockException (abs.backend.java.lib.runtime.ABSDeadlockException)1 ABSException (abs.backend.java.lib.runtime.ABSException)1 Task (abs.backend.java.lib.runtime.Task)1 SimpleSchedulerThread (abs.backend.java.scheduling.SimpleTaskScheduler.SimpleSchedulerThread)1 HashSet (java.util.HashSet)1