Reputation: 30088
while being stuck in some c**p SM code I ended up wondering is there a name for state machine that does actions that cause further inputs?
For example action on transition Start--(PowerOn)-->Initialized
might cause Play
to be generated and than state machine will get Play as input and do the transition Initialized--(Play) -->Playing
.
So Im kind of a need for name of this kind of machine so I could turn it more into what I consider a normal SM(aka SM that does transitions depending on input, ofc actions on transitions are also OK as long as they dont end up affecting the input).
It this is too abstract : I have a "SM" that sends and receives msgs, problem is that sending part causes replies that are than processed as input. That makes it hard to reason about behavior of the machine, which in turn makes modification of the code hard.
Upvotes: 3
Views: 187
Reputation: 28747
They are named:
Recursive state machines (RSMs).
Further Info see http://research.microsoft.com/en-us/um/people/pg/public_psfiles/toplas2005.pdf
Upvotes: 3
Reputation: 1705
If you're worried about the state-machine recursively invoking itself, how about this:
Implementing the state-machine as it was suggested in the article I linked to in the comments, you'd have a Moore style output function, a Mealy style output function, a transition function, and a next-state determination function.
You could then combine this with the queueing technique as described by Ambroz Bizjak in a long stack overflow post or a shorter (but somewhat more concise) programmers.stackexchange post to queue incoming input to the machine, and then have the machine transition function loop and block waiting for input in this queue. All input to the machine should be queued into the queue rather than invoking the transition function directly; that way, any outputs that would cause new input to occur would queue the input rather than doing a recursive transition call.
You might also try splitting your machine into a transmission machine and a reception machine, and then have a sort of u
structure:
input output
| ^
v |
+---------+ +---------+
| rx | | tx |
| machine |-->| machine |
+---------+ +---------+
This would help separate the logic a bit. This has worked for me in the past.
As for a name for this scenario? I don't know of any.
Upvotes: 0