So I'm modifying a code to be multithreaded, I have read several articles but have not found my answer, I have the Main, Class A, Class B, now I want to know if it's possible to program threads in class b so when when main calls class a this in turn calls class b and here the treads are created, not from the main from the subclasses. Thanks.
Main
fr.place_sequences_to_nodes(&sequences,&leaf_nodes,reference_alignment,data_type);
int count = 1; root->name_internal_nodes(&count);
root->start_alignment(&mf);
ss.str(string());
ss << "Time main::align: "<< double(clock()-t_start)/CLOCKS_PER_SEC <<"\n";
Log_output::write_out(ss.str(),"time");
Node
void align_sequences(Model_factory *mf)
{
if(leaf) return;
left_child->align_sequences(mf);
right_child->align_sequences(mf);
this->align_sequences_this_node(mf);
}
Threads are independent, regardless of which other thread creates them. They are all the same. Thread A can create thread B which creates thread C which creates thread D and all of them will be the same kind of thread.
You can create them from wherever you want, just follow the documentation and remember the caveats (such as using a scoped_ptr to an RAII thread object which goes out of scope, causing the object to crash).