【问题标题】:boost msm usage of stop()提高 stop() 的 msm 使用率
【发布时间】:2021-09-29 15:23:22
【问题描述】:

我注意到使用 boost::msm 时,停止函数的行为与我预期的不同。 假设我愿意

    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);

我希望在停止之后不再处理任何事件。但是这里的输出是

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

完整的例子在这里https://godbolt.org/z/o88ze6641

如果 stop() 不阻止状态机接受进一步的事件,它的用途是什么? 我知道它会触发当前状态的 on_exit,但是离开后重新进入状态对我来说似乎很奇怪。

【问题讨论】:

标签: boost boost-msm


【解决方案1】:

我知道它触发了当前状态的on_exit

没错,就是the point of the method。

但是离开后重新进入状态对我来说似乎很奇怪。

嗯,如果是因为stop() 而发生的,那是奇怪的。但事实并非如此:那只是因为您处理了另一个事件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-13
    • 1970-01-01
    • 1970-01-01
    • 2020-04-09
    相关资源
    最近更新 更多