Boost logo

Boost Users :

From: Andreas Huber (ahd6974-spamboostorgtrap_at_[hidden])
Date: 2007-07-26 04:58:23


> 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 list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net