Search in sources :

Example 1 with Task

use of abs.backend.java.lib.runtime.Task in project abstools by abstools.

the class NetCOG method processMsg.

synchronized void processMsg(Msg msg) {
    if (msg instanceof CallMsg) {
        CallMsg cm = (CallMsg) msg;
        // FIXME: create task and replace promises with futures
        Task<?> task = new Task(cm.call);
        addTask(task);
    } else {
        PromiseMsg pm = (PromiseMsg) msg;
        promises.put(pm.promise, pm.value);
        ABSFut<? super ABSValue> f = futureMap.get(pm.promise);
        if (f != null) {
            f.resolve(pm.value);
        }
    }
}
Also used : PromiseMsg(abs.backend.java.lib.net.msg.PromiseMsg) Task(abs.backend.java.lib.runtime.Task) CallMsg(abs.backend.java.lib.net.msg.CallMsg)

Example 2 with Task

use of abs.backend.java.lib.runtime.Task 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

Task (abs.backend.java.lib.runtime.Task)2 CallMsg (abs.backend.java.lib.net.msg.CallMsg)1 PromiseMsg (abs.backend.java.lib.net.msg.PromiseMsg)1 ABSDeadlockException (abs.backend.java.lib.runtime.ABSDeadlockException)1 ABSException (abs.backend.java.lib.runtime.ABSException)1 SimpleSchedulerThread (abs.backend.java.scheduling.SimpleTaskScheduler.SimpleSchedulerThread)1 HashSet (java.util.HashSet)1