Reputation: 12273
Using the traditional definition of state machines, can state machine records be in multiple states at the same time? For example, if I have a User
model, can users be in both a subscriber
and in a promotional_period
state at the same time?
Note, I am not asking if it makes sense to do this, my question is - is it possible with state machines.
Upvotes: 21
Views: 14555
Reputation: 1037
Petri nets are a generalization of state machines that allow multiple simultaneous 'states'.
Upvotes: 2
Reputation: 7785
All the answers saying "no" are only correct if you are assuming the "typical" type of finite state machines (FSMs) known as deterministic finite automata (DFAs), which can only have a single active state at any given time.
However, this is not the only type of FSMs, and there is no good reason to restrict yourself to this type of mechanism in all cases. There are also nondeterministic finite automata (NFAs), which can be in any number of states simultaneously.
This isn't just academic, or even really about parsing (as the wikipedia links might imply): NFAs are actually quite simple and incredibly useful and are used in practice all over the place in both hardware and software implementations.
Basically, to design an NFA, you do it just like a DFA, but instead of having a "current state" and using the inputs to compute a "next state", you have a "current state set" and use the inputs to compute a "next state set". In hardware (e.g. FPGAs implemented in VHDL) this can be done literally simultaneously. In (single-threaded) software, this is typically done by just iterating through the current states in each "step" of the machine.
Upvotes: 47
Reputation: 1170
No. State machines have one state at a time.
A combination state could be done with another state, like subscriber_and_promotional_period
. This is the usual way to do it.
Upvotes: 5
Reputation: 21793
Quoth the Wikipedia for one day more:
"A finite-state machine (FSM) or finite-state automaton (plural: automata), or simply a state machine, is a mathematical model of computation used to design both computer programs and sequential logic circuits. It is conceived as an abstract machine that can be in one of a finite number of states. The machine is in only one state at a time; the state it is in at any given time is called the current state."
So, no.
Upvotes: 4