Boost C++ Libraries: Ticket #9280: handling deferred events https://svn.boost.org/trac10/ticket/9280 <p> My FSM has two states(connected, disconnected). One of the states is submachine with number of other substates. One of this substates has deferred events specified. </p> <p> When my root machine goes from state with submachine(connected) to disconnected, should any deferred events be cleared? If no, then why when we enter back in st_connected, deferred events are not handled immediately? MSM process them only after processing normal event(I think that after processing events MSM check if there are any deferred events). </p> <p> In test case I expect either no output after string 'On cmd with reply: 5' (when right behaviour is to clear deferred events), or 'On cmd with reply: 1' (when right behaviour is to process all deferred events on entry into st_connected state). </p> <p> Tested on 1.51, 1.53, trunk. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9280 Trac 1.4.3 Dmitry Banschikov <me@…> Mon, 21 Oct 2013 15:12:18 GMT attachment set https://svn.boost.org/trac10/ticket/9280 https://svn.boost.org/trac10/ticket/9280 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">main.cc</span> </li> </ul> <p> Processing of deferred events for submachine </p> Ticket Christophe Henry Mon, 18 Nov 2013 22:14:25 GMT status changed https://svn.boost.org/trac10/ticket/9280#comment:1 https://svn.boost.org/trac10/ticket/9280#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> <p> Correct, this is a bug, precisely, entering the submachine does not check for waiting deferred events. This would be solved by adding inside do_entry inside state_machine.hpp: </p> <p> handle_defer_helper&lt;library_sm&gt; defer_helper(m_deferred_events_queue); defer_helper.do_post_handle_deferred(HANDLED_TRUE); </p> <p> before : process_message_queue(this); </p> <p> This will have for effect that MSM will process ev_async_send_cmd_with_reply(1) when entering, and ev_async_send_cmd_with_reply(2) will be the last displayed text. </p> <p> But frankly, after seeing this, I'm unsure whether it's a great idea to keep deferred events while leaving the submachine, I need to think about it. </p> <p> To check if it solves your problem, I committed this fix in trunk rev. 86759. </p> Ticket Dmitry Banschikov <me@…> Tue, 19 Nov 2013 07:51:45 GMT <link>https://svn.boost.org/trac10/ticket/9280#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9280#comment:2</guid> <description> <p> Yes, with rev. 86759 output of test case is more expected. Actually, I need all deferred events be cleared on exit from state. For such behaviour I use this workaround: </p> <pre class="wiki"> template &lt;class Event, class Fsm&gt; void on_exit(Event const&amp;, Fsm&amp; fsm) { std::cout &lt;&lt; "On exit" &lt;&lt; std::endl; op_.reset(); fsm.template get_state&lt;test_machine_front_t::st_connected&amp;&gt;().get_deferred_queue().clear(); } </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>Christophe Henry</dc:creator> <pubDate>Sat, 23 Nov 2013 20:52:29 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9280#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9280#comment:3</guid> <description> <p> Ok, next possible solution, should make most happy: the decision of throwing away the deferred events upon exit is made by the history policy: </p> <ul><li><a class="missing wiki">NoHistory</a>: logically, we throw deferred events </li><li><a class="missing wiki">AlwaysHistory</a>: keep them all </li><li><a class="missing wiki">ShallowHistory</a>: like <a class="missing wiki">AlwayHistory</a>, but depending on the event. </li></ul><p> I committed to trunk, rev. 86799 (let's see if I get the last commit to svn ever ;-) ). Hope it solves your problem. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Christophe Henry</dc:creator> <pubDate>Sat, 23 Nov 2013 20:52:47 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/9280#comment:4 https://svn.boost.org/trac10/ticket/9280#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> Ticket