Boost logo

Boost :

Subject: Re: [boost] [MSM] Is there any interest in C++14 Boost.MSM-eUML like library which compiles up to 60x quicker whilst being a slightly faster too?
From: Kris (krzysztof_at_[hidden])
Date: 2016-02-09 15:19:49


On Tue, Feb 9, 2016 at 5:13 PM, Vicente Botet [via Boost] <
ml-node+s2283326n4683364h3_at_[hidden]> wrote:

> Le 08/02/2016 20:32, Kris a écrit :
>
> > On Sat, Feb 6, 2016 at 10:34 PM, Vicente Botet [via Boost] <
> > [hidden email] <http:///user/SendEmail.jtp?type=node&node=4683364&i=0>>
> wrote:
> >
> >> src + event [guard]/action = dst // guard throws runtime_error
> >> src + exception<runtime_error> = X // handle exception
> >> Yes, this is the idea.
> >
> > Great. I have improved error handling if it comes to exceptions.
> > Right now, if you do NOT compile with `-fno-exceptions` and do not
> specify
> > configure noexcept then you can handle any exceptions thrown on the
> > transition table.
> >
> > make_transition_table(
> > *"idle"_s + "event1"_t / [] { throw std::runtime_error{"error"}; }
> > , "idle"_s + "event2"_t / [] { throw 0; }
> >
> > , *"error_handling"_s + exception<std::runtime_error> / [] {
> std::cout <<
> > "exception caught" << std::endl; }
> > , "error_handling"_s + exception<> / [] { std::cout << "generic
> > exception caught, terminate..." << std::endl; } = X
> > );
> I missed the syntax for the orthogonal regions. It is not very explicit.

Well, you can make it more explicit if you wish by changing the syntax a bit

     (*"idle"_s) + "event1"_t / [] { throw std::runtime_error{"error"}; }
    , "idle"_s + "event2"_t / [] { throw 0; }

//---------------------------------------------------------------------------------------------------------/
   , (*"error_handling"_s) + exception<std::runtime_error> / [] { }

> The idea to have an orthogonal section that does the error handling is
> good, but how would you do error recovery?
>
>
Well, it depends whether you have to or not recover out of it. If you
don't, another orthogonal region which will do the cleanup is good enough.
However, if you do have to recover I would use another state for it, as you
suggested.

make_transition_table(
    (*"idle"_s) + "event1"_t / [] { throw std::runtime_error{"error"}; }
   , "idle"_s + "event2"_t / [] { throw 0; }
   , "idle"_s + exception<std::runtime_error> / [] { ... } = "recover"_s
   , "recover"_s + "okay"_t = "idle"_s // fine now
);

> I don't think you should correlate whether MSM manage exceptions and
> whether the configure function is noexcept.
>
>
Why not? I find it better then being forced to setup some dummy type in the
state machine to enable exception handling.
Please notice that exceptions handling is enabled by default (unless you
compile with -fno-exceptions). The only reason why
noexcept with configure when you create a transition table counts its
because it will give you more performance.

> When you say " When guard/action throws an exception State Machine
> <<a href="
> http://boost-experimental.github.io/msm-lite/user_guide/index.html##sm-state-machine
> ">
> http://boost-experimental.github.io/msm-lite/user_guide/index.html##sm-state-machine>
>
> will stay in a current state.", do you mean that if there is an
> exception in the action part, the state will be the nesting state of the
> transition, as the exit of the source state will already be executed? If
> yes, this is not a leaf state, this is why I added a pseudo-state, to
> ensure a leaf state.
>

It means that if exception won't be handled and that source state will
remains the current state.
Exit of the source state won't happen in such case too. Change the state
happens
after guards/actions were executed properly, otherwise source state is
still a current state.

src_state + event [ guard ] / action = dst_state
                                                    ^
                                                    |
                                                  1. src_state + on_exit
                                                  2. dst_state + on_entry

>
> > You can handle specific type of the exception(exception<type>) or just
> > any(exception<>).
> What would be the event associated to the action in this cases?
>
>
Simply, none. It won't compile when you try to add action/guard with the
event for this transition.
In case of exception<>:

auto guard = [] (auto event) {} // won't compile
auto guard = [] () {} // okay

However, you can get some info about the exception using
std::current_exception

auto action = [] () {
    auto exptr = std::current_exception();
    ...
}

>
> >>> Okay, well, msm-lite doesn't support that as a feature. However, you
> can
> >>> achieve more or less all of mentioned things just by using C++.
> >>> For example, you can extend transiton table of a state machine by
> >> joining
> >>> it with another one.
> >>>
> >>> auto table1 = make_transition_table(transitions...);
> >>> auto table2 = make_transition_table(table1, other_transitions...);
> >>>
> >> This should respond to point 1*. 2* should need to replace the refined
> >> state in table1.
> >> Point 3 would covered if the make_transition_table function overrides
> >> the redefined transitions.
> >>
> > I was wondering whether your point with extending transitions can't be
> > achieved using sub machines instead ?
> This is another mechanism of extension that of course should work also,
> but that is not related to the previous 5 extensions mechanisms
>
> >> It would be great if you show how the user can address these points
> with
> >> your library using some run-able concrete examples.
> >>
> > Yea, I will work on that. Cheers for the pointers.
> >
> >
> Thanks for working on this.
>

Np

> Vicente
>
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
>
> http://boost.2283326.n4.nabble.com/MSM-Is-there-any-interest-in-C-14-Boost-MSM-eUML-like-library-which-compiles-up-to-60x-quicker-whils-tp4683016p4683364.html
> To unsubscribe from [MSM] Is there any interest in C++14 Boost.MSM-eUML
> like library which compiles up to 60x quicker whilst being a slightly
> faster too?, click here
> <http://boost.2283326.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4683016&code=a3J6eXN6dG9mQGp1c2lhay5uZXR8NDY4MzAxNnwtMTY0MTkzNTIwMA==>
> .
> NAML
> <http://boost.2283326.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>

--
View this message in context: http://boost.2283326.n4.nabble.com/MSM-Is-there-any-interest-in-C-14-Boost-MSM-eUML-like-library-which-compiles-up-to-60x-quicker-whils-tp4683016p4683369.html
Sent from the Boost - Dev mailing list archive at Nabble.com.

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