boost msm usage of stop()

131 Views Asked by At

I noticed that with boost::msm the stop function behaves different than I expected. Lets say I do

    sm state_machine;
    state_machine.start(); 
    state_machine.process_event(event_a()); pstate(state_machine);
    
    std::cout << "stop sm" << std::endl;
    state_machine.stop();

    std::cout << "process_event after stop!" << std::endl;

    state_machine.process_event(event_b()); pstate(state_machine);

I would expect that after the stop no further events are processed. However the output here is

entering: State Maschine
entering: state_a
leaving: state_a
action a->b
entering: state_b
-> B
stop sm
leaving: state_b
leaving: State Maschine
process_event after stop!
leaving: state_b
action b->a
entering: state_a
-> A

The full example is here https://godbolt.org/z/o88ze6641

What is the usage for stop() if it does not prevent the state machine from accepting further events? I know that it triggers the on_exit of the current state but the reentry into a state after leaving seems strange to me.

1

There are 1 best solutions below

0
On

I know that it triggers the on_exit of the current state

Exactly, that's the point of the method.

but the reentry into a state after leaving seems strange to me.

Well, that is strange, if it happened due to stop(). But that's not the case: that's only because you process another event.