Search in sources :

Example 1 with StartBThread

use of il.ac.bgu.cs.bp.bpjs.execution.tasks.StartBThread in project BPjs by bThink-BGU.

the class BProgramSyncSnapshot method start.

/**
 * Starts the BProgram - runs all the registered b-threads to their first
 * {@code bsync}.
 *
 * @param exSvc the executor service that will advance the threads.
 * @return A snapshot of the program at the first {@code bsync}.
 * @throws java.lang.InterruptedException
 */
public BProgramSyncSnapshot start(ExecutorService exSvc) throws InterruptedException {
    Set<BThreadSyncSnapshot> nextRound = new HashSet<>(threadSnapshots.size());
    BPEngineTask.Listener halter = new HaltOnAssertion(exSvc);
    nextRound.addAll(exSvc.invokeAll(threadSnapshots.stream().map(bt -> new StartBThread(bt, halter)).collect(toList())).stream().map(f -> safeGet(f)).collect(toList()));
    // FIXME test for assertion failures
    executeAllAddedBThreads(nextRound, exSvc, halter);
    List<BEvent> nextExternalEvents = new ArrayList<>(getExternalEvents());
    nextExternalEvents.addAll(bprog.drainEnqueuedExternalEvents());
    return new BProgramSyncSnapshot(bprog, nextRound, nextExternalEvents, violationRecord.get());
}
Also used : ArrayList(java.util.ArrayList) StartBThread(il.ac.bgu.cs.bp.bpjs.execution.tasks.StartBThread) BPEngineTask(il.ac.bgu.cs.bp.bpjs.execution.tasks.BPEngineTask) HashSet(java.util.HashSet)

Aggregations

BPEngineTask (il.ac.bgu.cs.bp.bpjs.execution.tasks.BPEngineTask)1 StartBThread (il.ac.bgu.cs.bp.bpjs.execution.tasks.StartBThread)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1