Reputation: 1005
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);
}
Upvotes: 0
Views: 157
Reputation: 3968
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).
Upvotes: 0
Reputation: 6359
You're mixing class and thread here and maybe confusing yourself... You'll have a single execution thread if your current application is single threaded. You can create more threads, the instance of the class they're created from shouldn't really matter (apart from scoping of the instance, potentially letting thread references drop out of scope so they'd be uncontrollable). Without an example, I can't say much more.
Upvotes: 3