Here's a bit more detail of my current problem.
I have implemented destructors within ClassA and ClassB. When adding this thread to the thread_group, the thread objects destructors are being called as soon as they're added to the thread_group.
struct MyStruct : ... {
boost::thread_group threads;
};
template <class Event, class FSM>
void psm_::MyEvent::on_entry(Event const& ev, FSM& sm)
{
auto bb = std::make_shared<bounded_buffer<MyData>>(100);
ClassA<bounded_buffer<MyData>> c_a(bb);
ClassB<bounded_buffer<MyData>> c_b(bb);
threads.add_thread(new boost::thread(c_a); // destructors called here
threads.add_thread(new boost::thread(c_b);
}
I've wrapped the thread_group within unique_ptr so that I can call reset, but I don't even make it to this point because the thread objects have already been destroyed when being added to the thread (and program exits).
template <class Event, class FSM>
void psm_::MyEvent::on_exit(Event const& ev, FSM& sm)
{
std::unique_ptr<boost::thread_group> tg(&threads);
tg.reset();
threads.interrupt_all();
threads.join_all();
}
And if I don't add the destructors to the thread objects (ClassA, ClassB), I am able to reach on_exit when I need to.
Any thoughts as to why the destructors (which I need to make use of in on_exit) are being called when adding the new threads?