0

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.

alex
  • 310
  • 1
  • 6
  • https://www.boost.org/doc/libs/1_76_0/libs/msm/doc/HTML/ch03s05.html#:~:text=The%20stop()%20method%20works%20the%20same%20way.%20It%20will%20cause%20the%20exit%20actions%20of%20the%20currently%20active%20states(s)%20to%20be%20called. – sehe Sep 29 '21 at 19:01

1 Answers1

0

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.

sehe
  • 374,641
  • 47
  • 450
  • 633