Mode Sets
Modes provide an additional level of specifying rule method enabling, which is convenient if the general structure of the state machine is already well known.
In each state, a model program is considered to be in a current set of modes, which is by default the empty set, particularly if modes are not used. A rule attribute can specify a transformation on this mode set, as in the following code example.
[Rule(Action="label", ModeTransition="Trans"]
Where the syntax definition for the string value of ModeTransition is as follows.
Trans ::= IdentList -> IdentList .
IdentList ::= Ident {, Ident } .
The left-hand side of the transformation is called the source mode set; the right-hand side is called the target mode set. A rule method is enabled in a state only if the source mode set is a subset of the state mode set and all other enabling conditions are satisfied. If the rule is invoked, the mode set for the target state is the mode set of the source state minus the source mode set, plus the target mode set. By this definition, a rule that has an empty source mode set is always enabled, at least regarding its mode-set enabling. This provides a usable default for models in which no mode sets are defined.
Identifiers used in mode sets are arbitrary and do not require a declaration.
Two further attributes are used in conjunction with modes. [InitialMode(modeList)] defines modes that are used for the initial state of the model program. If it is not specified, the initial mode set is empty. [AcceptingMode(modeList)] defines a subset of modes for a state to be an accepting state. This attribute can appear more than once, in which case the result is the disjunction of the sets provided in all occurrences. A state is accepting if its mode list for any AcceptingMode attribute is a subset of the mode set of the state. [ErrorMode(modeList)] defines modes that are marked as an error state when the intersection of the current mode set of a state with the mode set is not empty.
Example
The following code example shows an excerpt from a model program that creates two sequences.
event Fork(); event Thread1(); event Thread2(); event Join()
event Fork(); event Thread2(); event Thread1(); event Join()
It shows that mode sets enable expression of parallel finite state machines.
[InitialMode("starting")]
[AcceptingMode("ended")]
class C
{
[Rule(Action = "Fork", ModeTransition = "starting->thread1Runs,thread2Runs")]
static void Fork() { }
[Rule(Action = "Thread1", ModeTransition = "thread1Runs->thread1Finished")]
static void Thread1() { }
[Rule(Action = "Thread2", ModeTransition = "thread2Runs->thread2Finished")]
static void Thread2() { }
[Rule(Action = "Join", ModeTransition = "thread1Finished,thread2Finished->ended")]
static void Join() { }
}
config Multithreaded
{
action abstract event static void ModelActions.Fork();
action abstract event static void ModelActions.Thread1();
action abstract event static void ModelActions.Thread2();
action abstract event static void ModelActions.Join();
}
machine M1() : Multithreaded
{
construct model program
}
See Also
Reference
InitialModeAttribute
AcceptingModeAttribute
ErrorModeAttribute