Boost logo

Boost :

From: Andreas Huber (ahd6974-spamboostorgtrap_at_[hidden])
Date: 2007-11-01 06:29:45


Hi Jurko

Thanks for your feedback.

> Just an idea: update the documentation to explicitly note that
> statechart using code should synchronize both processEvent() and
> terminate() calls when using a single statechart from multiple threads.

The fact that none of the state_machine methods are reentrant (and therefore
also not thread-safe) is mentioned in the turtorial:

<http://www.boost.org/libs/statechart/doc/tutorial.html#AsynchronousStateMachine
s>

> We just solved a bug in one of our projects using the statechart
> library where we forgot to synchronize the terminate() call. Was causing
> non-reproducible assertion failures in the termination code.

Note that you'd have to synchronize access to *all* state_machine member
functions.
Moreover, it's usually suboptimal to just protect access to a state_machine
subtype object with a mutex. This approach scales badly when events for the
same state machine originate in multiple different threads (as they seem in
your application).
Also, if you happen to have multiple cores a lot of the processing that could
be parallelized is not and thus leads to even worse performance.
Both problems can be overcome with a scheduler, which is essentially a
combination of an event queue with a dedicated worker thread (see link above).

Regards,

Andreas


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk