[statechart] asynchronous machine's post event question.

Hi,
According to the code
struct Working:sc::state< Working, Active >
{
Working(my_context ctx):my_base(ctx)
{
cout<<__FUNCTION__<

According to the code struct Working:sc::state< Working, Active > { Working(my_context ctx):my_base(ctx) { cout<<__FUNCTION__<
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.
participants (2)
-
Andreas Huber
-
Jiang Miao