some newbie-questions concerning multithreading...
I have a script-interpreter-class (clsParser) with severai. nested instances. Most script-executions are triggert by events or parent-instances. Now i want to deligate some of these calls to parallel threads. Therefore i created a small class (clsParserThread) derived from wxThread, that is instanced like this: clsParserThread(clsParser *parser, char *code).
clsParser has a method clsParser::Exec(char *Code). This i've put into the Entry()-function of clsParserThread, like this:
Code: Select all
clsParserThread::ExitCode clsParserThread::Entry() {
Parser->Exec(Code);
return NULL;
}
My questions:
First of all: Instead of calling Parser->Exec(Code);, i now want to use this call: (new clsParserThread(Parser,Code))->Entry(); Is this correct so far, which means, is the ecexution of 'Code' by 'clsParserThread' done parallel to the continued execution of the calling (parent) clsParser?
Will all child-instances of parser be executed parallel, if i start several clsParserThreads in a loop like this:
Code: Select all
for (int i=0; i < CountChildren(); i++) (new clsParserThread (ChildParser[i], Code[i]))->Entry();
What happens if i use the stack instead of the heap, like this:
Code: Select all
for (int i=0; i < CountChildren(); i++) clsParserThread (ChildParser[i], Code[i]).Entry();
Thank you,
Frank