Files @ a3c92705eeee
Branch filter:

Location: CSY/reowolf/testdata/parser/positive/2.pdl

Christopher Esterhuyse
bugfix: native component branch forks that clash are MERGED rather than overwritten. Avoids race condition where (1) branch x ends and submits a solution, (2) branch y is created, has same predicate as x and overwrites it, but has a subset of its messages, (3) round ends in success but branch x is gone, so no suitable native branch is found
#version 100

import std.reo;

composite main(in asend, out arecv, in bsend, out brecv, in csend, out crecv) {
    channel xo -> xi;
    channel yo -> yi;
    channel zo -> zi;
    // Every synchronous round, at most one message is sent (to determine a global order)
    new mymerger(asend, bsend, xo);
    new mymerger(csend, xi, yo);
    // If a message is sent, it is broadcast to every recipient
    new replicator(yi, {arecv, zo});
    new replicator(zi, {brecv, crecv});
}

primitive mymerger(in a, in b, out c) {
    while (true) {
        synchronous {
            if (fires(a) && !fires(b) && fires(c)) {
                put(c, get(a));
            } else if (!fires(a) && fires(b) && fires(c)) {
                put(c, get(b));
            } else {
            	assert !fires(a) && !fires(b) && !fires(c);
            }
        }
    }
}