Boost logo

Boost-Commit :

From: ahd6974-boostorg_at_[hidden]
Date: 2008-01-02 15:31:43


Author: andreas_huber69
Date: 2008-01-02 15:31:42 EST (Wed, 02 Jan 2008)
New Revision: 42417
URL: http://svn.boost.org/trac/boost/changeset/42417

Log:
Added a new FAQ item.
Text files modified:
   trunk/libs/statechart/doc/faq.html | 40 ++++++++++++++++++++++++++++++++++++++--
   trunk/libs/statechart/doc/future_and_history.html | 7 ++++---
   2 files changed, 42 insertions(+), 5 deletions(-)

Modified: trunk/libs/statechart/doc/faq.html
==============================================================================
--- trunk/libs/statechart/doc/faq.html (original)
+++ trunk/libs/statechart/doc/faq.html 2008-01-02 15:31:42 EST (Wed, 02 Jan 2008)
@@ -40,6 +40,9 @@
     state machine and modify its layout in the subclass?</a></dt>
 
     <dt>What about UML2.0 features?</dt>
+
+ <dt><a href="#AssertInStateDestructor">Why do I get an assert when I
+ access the state machine from a state destructor?</a></dt>
 
     <dt><a href="#EmbeddedApplications">Is Boost.Statechart suitable for
     embedded applications?</a></dt>
@@ -313,6 +316,40 @@
     transition destination as a template parameter)</li>
   </ul>
 
+ <h2><a name="AssertInStateDestructor" id="AssertInStateDestructor">Why do I
+ get an assert when I access the state machine from a state destructor?</a>
+ </h2>
+
+ <p>When compiled with <code>NDEBUG</code> undefined, running the following
+ program results in a failed assert:</p>
+ <pre>#include &lt;boost/statechart/state_machine.hpp&gt;
+#include &lt;boost/statechart/simple_state.hpp&gt;
+#include &lt;iostream&gt;
+
+struct Initial;
+struct Machine : boost::statechart::state_machine&lt; Machine, Initial &gt;
+{
+ Machine() { someMember_ = 42; }
+ int someMember_;
+};
+
+struct Initial : boost::statechart::simple_state&lt; Initial, Machine &gt;
+{
+ ~Initial() { std::cout &lt;&lt; outermost_context().someMember_; }
+};
+
+int main()
+{
+ Machine().initiate();
+ return 0;
+}</pre>
+ <p>The problem arises because <code>state_machine<>::~state_machine</code>
+ inevitably destructs all remaining active states. At this time,
+ <code>Machine::~Machine</code> has already been run, making it illegal to
+ access any of the <code>Machine</code> members. This problem can be avoided
+ by defining the following destructor:</p>
+ <pre>~Machine() { terminate(); }</pre>
+
   <h2><a name="EmbeddedApplications" id="EmbeddedApplications">Is
   Boost.Statechart suitable for embedded applications?</a></h2>
 
@@ -516,14 +553,13 @@
   and <a href=
   "reference.html#clear_deep_history">simple_state::clear_deep_history()</a>.
   Calling these functions is often preferable to introducting additional
- normal transitions when ...
+ normal transitions when ...</p>
   <ul>
     <li>a state with history is the target of many transitions,
     <b>and/or</b></li>
     <li>the decision to ignore history is made in a different place than
     the transition to a state with history</li>
   </ul>
- </p>
 
   <h2><a name="Dll" id="Dll">How can I compile a state machine into a dynamic
   link library (DLL)?</a></h2>

Modified: trunk/libs/statechart/doc/future_and_history.html
==============================================================================
--- trunk/libs/statechart/doc/future_and_history.html (original)
+++ trunk/libs/statechart/doc/future_and_history.html 2008-01-02 15:31:42 EST (Wed, 02 Jan 2008)
@@ -139,16 +139,18 @@
 
   <p>(<font color="#FF0000">red</font> = points raised during formal
   review)</p>
- <p>Unreleased (commited to the SVN trunk)</p>
+ <p>Unreleased (committed to the SVN trunk)</p>
   <ul>
     <li>Removed all permanent warning suppressions from library headers
       and avoided the resulting warnings with other means (suggested by
       Steven Watanabe; thanks to Peter Dimov and Yuval Ronen for insight
       into when C4511 & C4512 are issued)</li>
+ <li>Added the FAQ item <a href="faq.html#AssertInStateDestructor">Why
+ do I get an assert when I access the state machine from a state
+ destructor?</a> (due to feedback from Jiang Miao)</li>
   </ul>
 
   <p>1.35.0</p>
-
   <ul>
     <li>Added placement new overload to <code>event&lt;&gt;</code> (due to
     feedback from Federico J. Fern&aacute;ndez)</li>
@@ -157,7 +159,6 @@
   </ul>
 
   <p>1.34.0</p>
-
   <ul>
     <li>Fixed a bug that prevented compilation of exception_translator.hpp
     (reported by Oliver Kowalke) and adapted TransitionTest.cpp to also test


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk