How to model Moore and Mealy machines with UML state diagrams? Besides, how to represent outputs in those diagrams? Through Actions?
UML state diagrams have the characteristics of both Mealy and Moore state machines.
To represent a pure Mealy machine, you use only actions on transitions:
stateA -- TRIGGER [guard] / action() --> stateB
To represent a pure Moore machine, you use only entry or exit actions to states, but you don't use actions on transitions:
stateA
entry/ actionA();
stateB
entry/ actionB();
When you use both actions on transitions and entry/exit actions in states, you have a mix of Mealy and Moore machines.
A statemachine can define behavior (p. 309 of the latest UML 2.5.1 specs):
14.2.3.4.3 State entry, exit, and doActivity Behaviors
A State may have an associated entry Behavior. This Behavior, if defined, is executed whenever the State is entered through an external Transition. In addition, a State may also have an associated exit Behavior, which, if defined, is executed whenever the State is exited.
A State may also have an associated doActivity Behavior. This Behavior commences execution when the State is entered (but only after the State entry Behavior has completed) and executes concurrently with any other Behaviors that may be associated with the State, until:
it completes (in which case a completion event is generated) or
the State is exited, in which case execution of the doActivity Behavior is aborted.
The execution of a doActivity Behavior of a State is not affected by the firing of an internal Transition of that State.
Read on at p. 320 about the notation of the latter.
Related
I know that action starts to execute upon the entry, and the actions executes for do as long it's in the state.
but I think there's a lack of definition for entry, is it similar to do or the action executes upon entry to the state and it keeps executing even after leaving the state?
From UML 2.5 p. 307:
14.2.3.4.3 State entry, exit, and doActivity Behaviors
A State may have an associated entry Behavior. This Behavior, if defined, is executed whenever the State is entered through an external Transition. In addition, a State may also have an associated exit Behavior, which, if defined, is executed whenever the State is exited.
A State may also have an associated doActivity Behavior. This Behavior commences execution when the State is entered (but only after the State entry Behavior has completed) and executes concurrently with any other Behaviors that may be associated with the State, until:
it completes (in which case a completion event is generated) or
the State is exited, in which case execution of the doActivity Behavior is aborted.
The execution of a doActivity Behavior of a State is not affected by the firing of an internal Transition of that State.
The UML standard states
terminate pseudostate
Entering a terminate pseudo state implies that
the execution of the state machine by means of its context object is
terminated. The state machine does not exit any states nor does it
perform any exit actions other than those associated with the
transition leading to the terminate pseudo state.
When should I use final and terminate pseudostate? For me terminate pseudostate can be replaced by a state with name "destroyed".
A lot of the explanations and examples out there are a bit cryptic, so let me see if I can put it in plainer English for you. A final state is where a process exits the state machine. A terminate pseudostate is one where the state machine shuts down.
One example might be a state machine for a cell phone call. You might have states such as find contact, initiate call, phone ringing, either go to voicemail or connect with contact, and then eventually to disconnect. In this case, the final state would be disconnect (or more correctly, disconnect would be the state that leads to the final state). Terminate pseudostates might be phone's battery dies, phone falls down garbage disposal, and so on.
I won't go so far as to say that a terminate pseudostate models an abnormal termination of a state machine, but that is what most practical applications of it use it for.
I did not understand the paradigm run-to-completion about state machine (14.2.3.9.1 UML 2.5 spec). At one point he says:
"Run-to-completion means that, in the absence of exceptions or asynchronous destruction of the context Classifier object or the StateMachine execution, a pending Event occurrence is dispatched only after the processing of the previous occurrence is completed and a stable state configuration has been reached. That is, an Event occurrence will never be dispatched while the StateMachine execution is busy processing the previous one"
and in another:
"IMPLEMENTATION NOTE. Run-to-completion is often mistakenly interpreted as implying that an executing StateMachine cannot be interrupted, which, of course [of course?? NDR] would lead to priority inversion issues in some time-sensitive systems. However, this is not the case; in a given implementation a thread executing a StateMachine step can be suspended, allowing higher-priority threads to run, and, once it is allocated processor time again by the underlying thread scheduler, it can safely resume its execution and complete its event processing"
So, is possible or not interrupt the state machine?? A new high priority event can interrupt the current event dispatch?
Thanks
Mauro
The implementation note refers to hard- or software implementation on a higher level. The completion is only valid for the context of the state machine. This machine may run in a global context which can allow to interrupt the processing of the state machine. But the state machine will not notice this interruption and from its own view it still continues processing. So, as mentioned, the only issue is that the state machines personal watch will not run continuously but with irregular jumps. In normal business processes this can be neglected, but when dealing with real-time-processing, you might get into trouble.
"an Event occurrence will never be dispatched while the StateMachine execution is busy processing the previous one" means that a StateMachine will not select the next Event from its queue until its run-to-completion step is completed. This does not prevent the state machine itself or other state machines from sending further events into its queue, while the run-to-completion step is running.
Moreover, a run-to-completion step might become suspended in the case of a synchronous Operation Call; the run-to-completion step will later be resumed when the operation call is completed (possibly returning a value).
I am reading 'The Art of Multiprocessor Programming'. Now, i get stuck at third chapter , because do not understand the notion of Quiescent Consistency.Can you give me a example to expain what is Quiescent Consistency?Please as clearly as possible!
In distributed programming, there is an approach to describe data
structure behavior known as quiescent consistency. There is a number
of consistency conditions, sequential consistency, linearizability and
others. These conditions describe how an object behaves when there are
several threads calling its methods.
A data structure possesses quiescent consistency if it is consistent
between its states of quiescence, i.e. when there are no methods
currently in progress. As soon as a quiescently consistent structure
has no operations pending (i.e. reaches the quiescence), we may be
sure that the executions of methods before this state and after this
state is never interpositioned.
An execution is quiescently consistent if the method calls can be
correctly arranged retaining the mutual order of calls separated by
quiescence, a period of time where no method is being called in any
thread.
Sources:
http://coldattic.info/shvedsky/pro/blogs/a-foo-walks-into-a-bar/posts/88
http://coldattic.info/shvedsky/pro/blogs/a-foo-walks-into-a-bar/posts/72
I was reading about the debuggerstepperboundary attribute and a site says it is is useful in a context switch.
What exactly is a context switch? I'm assuming it is a switch from one thread to another, or in execution or security context? However, these are not particularly educated guesses so I'm asking here.
A context switch (also sometimes referred to as a process switch or a task switch) is the switching of the CPU (central processing unit) from one process or thread to another.
Context switching can be described in slightly more detail as the kernel (i.e., the core of the operating system) performing the following activities with regard to processes (including threads) on the CPU: (1) suspending the progression of one process and storing the CPU's state (i.e., the context) for that process somewhere in memory, (2) retrieving the context of the next process from memory and restoring it in the CPU's registers and (3) returning to the location indicated by the program counter (i.e., returning to the line of code at which the process was interrupted) in order to resume the process.
A context switch is sometimes described as the kernel suspending execution of one process on the CPU and resuming execution of some other process that had previously been suspended. Although this wording can help clarify the concept, it can be confusing in itself because a process is, by definition, an executing instance of a program. Thus the wording suspending progression of a process might be preferable.
Context switch is the switching of the CPU from one process/thread to another process/thread.
People sometimes use the term context switch outside of the specific computer world to reflect what they are doing in their own lives. "If I am going to answer that question, I need to context switch from thinking about A to thinking about B".
Wikipedia
It usually refers to switching between threads or processes. Wikipedia has a more thorough description.
It is the process of switching between processes on a CPU.
Switching the CPU core to another process requires performing a state
save of the current process and a state restore of a different
process. This task is known as a context switch
Excerpted from: Operating System Concepts, Abraham (Dinosaurs coverpage)
But it doesn't necessarily help me to understand the concept. I like to see animations or images as studying. So, the RTOS's link is genuinely helpful.