Aug 21, 2011 at 9:23am UTC
EDIT : it has belatedly sunk in that you are waiting for the threads to exit.
But I would probably still avoid passing the address of a local variable to a thread.
What do you mean by "failed terribadly" ?? (as in, what happened?)
And I would be careful with your returns. What happens if the first thread succeeds but the second doesn't.
Andy
Original attempt...
thread_message1 and thread_message2 are pointing at local variables.
1 2
string thread_Msg1 = "A new Thread has been created!!!" ; // LOCAL variable!
string * thread_message1 = &thread_Msg1;
So, if the thread continues to run after threadGen() exits, it will be ttempting to use a variable that no longer exists.
Use new instead (e.g.)
1 2
const char thread_Msg1[] = "A new Thread has been created!!!" ; // LOCAL variable!
string * thread_message1 = new string(thread_Msg1);
Note that, before it exits, the thread should delete the string you passed it.
Last edited on Aug 21, 2011 at 9:57am UTC
Aug 21, 2011 at 5:03pm UTC
Hey thx for the info, in other words can I create multiple names using these method?
Aug 21, 2011 at 5:15pm UTC
You can pass whatever strings (or other data) you want to your threads, as long as you take care of the variables' lifetimes.
Did your app crash?
(Actually -- following on from TheCreator's following message -- what do you want to use the names for?)
Last edited on Aug 21, 2011 at 11:59pm UTC
Aug 21, 2011 at 10:33pm UTC
you dont needs names
you can reference them through their PID