Anti-pattern: persist state machines

The following classes represent types of values ("data types"):

    String, Matrix, Map, Tuple, Relation, Point

The following classes represent types of state machines

    Thread, ThreadPool, Mutex, ConditionVariable, PrinterProxy, Button, Window

Note: by state machine we actually mean a non-trivial state machine. A variable of some datatype can be regarded as a trivial state machine that can transition from any state to any other state by assignment.

It is hardly ever a good idea to persist state machines.

A consistent cut is formalised by considering states to correspond to the set of events producing that state. A happened-before partial order is defined on the events according to whether one event potentially affected another. A consistent cut requires causality to be preserved - by not allowing an event in the "future" of the cut to have happened-before an event in the "past" of the cut.

In the following picture, the green cut is a consistent cut, the red cut is not because there is an event b2 in the future which precedes an event a3 in the past:

States That Preserve Causality

It is extremely onerous to find consistent cuts for a set of interacting state machines within a running process.

A consistent global state is defined in terms of a consistent cut. The global state is the state of each state machine, together with the messages currently in transit.

See Consistent Global States of Distributed Systems: Fundamental Concepts and Mechanisms