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.
struct MyEvent : public msm::front::state<>
{
template
void on_entry(Event const&, FSM&);
template
void on_exit(Event const&, FSM&);
boost::thread_group threads;
};
template
void psm_::MyEvent::on_entry(Event const& ev, FSM& sm)
{
auto bb = std::make_shared(100);
ClassA c_a(bb);
ClassB c_b(bb);
threads.add_thread(new boost::thread(c_a));
threads.add_thread(new boost::thread(c_b));
}
template
void psm_::MyEvent::on_exit(Event const& ev, FSM& sm)
{
threads.interrupt_all();
threads.join_all();
}
template <class Buffer>
class ClassB
{
private:
typedef typename Buffer::value_type value_type;
shared_ptr<Buffer> m_container;
public:
ClassB(shared_ptr<Buffer> buffer) : m_container(buffer) { }
~ClassB() { // ... }
void operator()() {
try {
// ... do stuff
boost::this_thread::interruption_point();
}
catch(const boost::thread_interrupted&) {
// ...
}
}
}