On 19/05/2015 15:26, Lane wrote:
I'm using the boost meta state machine and upon entry of this state, I create two threads, and stop these threads in the on_exit().
In on_entry(), I call the functors of each class and create threads and add those to a boost thread_group. What I need to do now is call the destructor of the objects on the threads ( of ClassA and ClassB) within on_exit(). I'm unclear as to how the destructors of the objects would/should be called when interrupting the threads. The destructors are currently not being called.
Since you are passing a copy of the object as the thread's state, the destructor for the local instances will be called in on_entry(), and the destructor for the instances owned by the thread will be called when the thread_group is destroyed, which is when MyEvent is destroyed. I'm not really familiar enough with Boost.MSM to know whether the event instance is destroyed when the event is handled (which if this were the case, you shouldn't be keeping threads in it), or when the containing state machine is destroyed, or only when the program exits.