Guardshift

Which guards wake up?

Change several signals in one patch. A guard wakes up only when its truth changes between the starting state and the final state.

Signal patch

One integer assignment per line. The last write to each signal wins.

Live signals

Initial state

Ready to apply

Guard transitions

All conditions in a row must hold. Both endpoints count.
GuardConditionsBeforeAfterEvent
Run the queue surge in C++17

Compare each guard before and after the entire patch. Guardshift returns the ID and new truth value of each changed guard. For the queue surge example, signals 0 and 1 represent queue depth and available workers.

#include "guardshift.hpp"
#include <iostream>

int main() {
    guardshift::Index index({18, 6}, {
        {{0, 20, 100}, {1, 1, 8}}, // Dispatch jobs
        {{0, 40, 100}, {1, 0, 2}}, // Request capacity
        {{0, 24, 36}},             // Watch midrange
        {{1, 4, 8}}                // Hold reserves
    });

    for (auto change : index.apply({{0, 58}, {1, 1}}))
        std::cout << change.guard << (change.active ? " entered" : " exited") << '\n';
}

The browser evaluates each guard directly to illustrate the transitions. The C++ library indexes guard intervals. The browser accepts integers within the displayed scales.