Re: [statechart] asynchronous machine's post event question.
> According to the code
> struct Working:sc::state< Working, Active >
> Working(my_context ctx):my_base(ctx)
> outermost_context_type& machine=outermost_context(); // machine is a
> A machine.post_event( EvtTerminate() );
> B machine.my_scheduler().queue_event( machine.my_handle
(),boost::intrusive_ptr<EvtTerminate>(new EvtTerminate() ) );
> 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
See above, you usually want option A.
When replying by private email, please remove the words spam and trap
from the address shown in the header.