Asynchronous state machine

State machine can be either synchronous or asynchronous.

Asynchronous state machine have a queue where events are stored, so that feeding the state machine never blocks the calling thread. Events are processed later, by the same or another thread, depending on the implementation. At any given time, there is only one thread processing the event queue. A clear separation exists between feeding the events and processing the events.

When to use an asynchronous state machine ?

A program is usually made of several state machines interconnected, the action of a state machine becomes an event for the other state machine and vice-versa. In this situation, state machines must be asynchronous.

How to specify an asynchronous state machine ?

The attribute asynchronous controls whether the state machine is asynchronous or synchronous

Asynchronous c++ state machine depends on third party library which provides an event loop and timer classes, the attribute library can be either qt, boost or libev

Synchronous versus asynchronous context

Synchronous context has public synchronous methods which correspond to the events that can be received.

Asynchronous context has public asynchronous methods and private synchronous methods with the suffix "Sync" for each event.

From the outside, synchronous and asynchronous context have the same API.

synchronous and asynchronous context