Big state machines

Vance Shipley vances@REDACTED
Tue Apr 19 07:44:24 CEST 2005

On Mon, Apr 18, 2005 at 10:03:59PM +0200, Ulf Wiger (AL/EAB) wrote:
}  .... Sadly, with UML and SDL, the default behaviour is to throw
}  away messages that arrive in the wrong state, and have not been
}  marked deferrable in that state. This makes it difficult to 
}  maintain large programs, unless the tool in question supports
}  another default (everything deferrable unless otherwise specified.)

I think it has to be this way.  You are always going to get late 
arrivals or other instances of messages you are not interested in.
If it weren't for these semantics you'd need to account for every
message the FSM handles in every state.  You'd also run the constant
risk of overflowing the mailbox.  Saving is the exceptional condition
done when you need to wait for a particular set of messages (e.g. ACK)
before proceeding.

On the other hand what I would like would require you to explicitly
throw away unwanted messages.  Ideally what I would like is just a
gen_fsm which had the sematics that if an event handler didn't match 
the first event in the queue it kept trying until it had tried all 
messages and then kept trying for new messages.  This way you would 
write normal states as:

idle(offhook, StateData) ->
    {next_state, dialtone};
idle(Event, StateData) ->
	{next_state, idle}.

When you want a state which saves signals you leave out the catchall

This may be no where near the pure erlang which you crave however it
would make it easier for me to translate SDL into gen_fsm.  Maybe this
isn't what I really want and I'm just too used to thinking in gen_fsm.
What I am doing is thinking in SDL though so the closer the semantic
leap is the better.


More information about the erlang-questions mailing list