[statechart] asynchronous machine's post event question.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[statechart] asynchronous machine's post event question.

jiangmiao
Hi,
According to the code

struct Working:sc::state< Working, Active >
    {
    Working(my_context ctx):my_base(ctx)
        {
        cout<<__FUNCTION__<<endl;
        outermost_context_type& machine=outermost_context(); // machine is a asynchronous machine.
A      machine.post_event( EvtTerminate() );
B      machine.my_scheduler().queue_event( machine.my_handle(),boost::intrusive_ptr<EvtTerminate>(new EvtTerminate() ) );
        };
    ~Working(void)
        {
        cout<<__FUNCTION__<<endl;
        }
    typedef sc::transition< EvtIdleWork,Idle > reactions;
    };

Is there any difference between A and B? Which is the better and recommended or Is there another better way to post event?

Thank you.

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [statechart] asynchronous machine's post event question.

Andreas Huber-3
> According to the code
> struct Working:sc::state< Working, Active >
> {
>   Working(my_context ctx):my_base(ctx)
>   {
>      cout<<__FUNCTION__<<endl;
>      outermost_context_type& machine=outermost_context(); // machine is a
asynchronous machine.
>      A machine.post_event( EvtTerminate() );
>      B machine.my_scheduler().queue_event( machine.my_handle
(),boost::intrusive_ptr<EvtTerminate>(new EvtTerminate() ) );
>   };
>   ~Working(void)
>   {
>      cout<<__FUNCTION__<<endl;
>   }
>
>   typedef sc::transition< EvtIdleWork,Idle > reactions;
> };
> Is there any difference between A and B?

Yes, there is. state_machiney<>.post_event is protected and puts events in a
queue that is private to the state machine. In an asynchronous state machine
the events in this queue always have absolute priority over events that are
queued through the scheduler.
fifo_scheduler<>.queue_event is public and puts all events in a queue that is
shared between all state machines that are serviced by the scheduler. Even if
fifo_scheduler services only one asynchronous_state_machine then events posted
with the B option in your example race with events posted from an external
source, which is useful only in rare circumstances (e.g. when you write your
own scheduler whose queue_event function accepts a time when the passed event
should be dispatched).

> Which is the better and recommended or Is there another better way to post
event?

See above, you usually want option A.

HTH,

--
Andreas Huber

When replying by private email, please remove the words spam and trap
from the address shown in the header.

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users