[statechart] Documentation update suggestion.

Hi. 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. 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. :-) Hope this helps. Best regards, Jurko Gospodnetić

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#AsynchronousStateMach... 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
participants (2)
-
Andreas Huber
-
Jurko Gospodnetić