ePrivacy and GPDR Cookie Consent by Cookie Consent

Asynchronous behavior

An asynchronous behavior is an abstraction for a behavior that is executed in its own context (thread). It is used by the asynchronous simple state to implement its do behavior.

How it is started

The asynchronous behavior starts automatically after the entry behavior of the asynchronous simple state is finished and thus the do behavior starts.

How it is stopped

The asynchronous behavior is stopped when

  • the task has been finished,

  • in case when an event was fired and the containing state is exited a reaction to this event, or

  • when the state machine is stopped.

How it is used

The user needs to subclass the asynchronous behavior class async_behavior, then override and implement the pure virtual method run_impl .

In order for the state machine to stop an async behavior, one of the following strategies must be implemented:

  • The run_impl method needs to regularly check if it has to stop by checking the return value of should_stop (e.g. by polling it in a loop).

  • Override the method notify_should_stop and take appropriate steps to finish run_impl (e.g. by notifying a condition variable and then checking should_stop).