/
3012QueuedStateMachines.txt
25 lines (19 loc) · 1.52 KB
/
3012QueuedStateMachines.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Queued State Machines
State Machines
noreferences
@@tooltip A queued state machine has separate threads to manage a queue of incoming events, and to do the resulting transitions, meaning that deadlock is less likely
@@description
<p>
Standard state machines operate in a single thread. When an event method is called, the state machine code that runs continues the same thread of the caller. This can be satisfactory for simple applications, but it doesn't work in multi-threaded environments, and can also result in deadlocks.
</p>
<p>
To overcome the above problems, a state machine may be declared as 'queued' by just placing the keyword queued before the declaration of the state machine. In a queued state machine, the calls to the event methods simply add a record to the queue, and then return. The calling thread can then continue and do other activities. A separate thread exists in each state machine to take events off the queue and process them, in the order they are received. The thread will only process the event at the head of the queue when in a state that has a transition corresponding to that event; otherwise it will wait until the state machine enters such a state.
</p>
<p>
A queued state machine will process events in the same order as a regular state machine. See also <a href="PooledStateMachines.html">pooled state machines</a> for a variation on this semantics.
</p>
@@syntax
[[inlineStateMachine]]
@@example
@@source manualexamples/QueuedStateMachines1.ump &diagramtype=state
@@endexample