Boost logo

Boost :

Subject: [boost] Boost MSM parallel behavior with delayed self-transitions?
From: Christophe Henry (christophe.j.henry_at_[hidden])
Date: 2017-03-21 20:11:50


Hi Danylo,

>Hi community,
>
> I am using Boost MSM (basic and functor front-ends) and am trying to
>implement the following state machine (https://i.stack.imgur.com/K79qk.png
):

Ok, State1 is itself a state machine (also called composite). See:
http://www.boost.org/doc/libs/1_63_0/libs/msm/doc/HTML/ch02s02.html#d0e151
and:
http://www.boost.org/doc/libs/1_63_0/libs/msm/doc/HTML/ch03s02.html#d0e529

Then you have 2 active states, which are called orthogonal regions. See:
http://www.boost.org/doc/libs/1_63_0/libs/msm/doc/HTML/ch03s02.html#d0e577

>I am using Boost MSM (basic and functor front-ends) and am trying to
>implement the following state machine: enter image description here
>
>In words:
< snip >
>
>I would like to know the way to create this state machine in Boost MSM.

The above link has an example.

>There are two tricks here which I cannot figure out how to do:
>
> - Execution in parallel (i.e. running action_A does not stop running
>action_B at the same time)

It depends what you mean with "in parallel". Having 2 active states means
that the actions execute only logically at the same time, meaning within
the same process_event call. But as you have just one thread, they will
execute after each other.
If you mean in different threads, then no, the library does not support
this. But my next library, Asynchronous does (
https://github.com/henry-ch/asynchronous).
I have examples with state machines, timer, etc.

>- Delayed transition (i.e. the transitions which happen after 2
>seconds for state A and after 5 seconds for state B). Neither delay
>should be blocking! The transitions should just "fire" after this time.

Sorry, this is out of scope of the library as it would involve threads. You
can do one of the following:
- use your own timer (Boost.Asio offers one) and handle thread safety
yourself.
- have a look at Asynchronous. Sorry if it looks like advertising, but the
library was written for this kind of things.

>Thank you very much for helping,
>
>Danylo.

HTH,
Christophe


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk