Hello all. I am working with threads at the moment in my program. The thread is simple and looks like this.

Thread oThread = gcnew Thread( new ThreadStart( this,&qualifiedlist::ThreadProc ) );
oThread->Start();

I have another simplar thread like this but its more complex. I try to set variables in it like this, for example.

int y;
void ThreadProc(void){

};


Thread oThread = new Thread( new ThreadStart( this,&qualifiedlist::ThreadProc ) );
oThread->Start();
cout<<y;

y will be 0!

This is veryyy simple stuff, but if i cout<<y; from outside of the ThreadProc it will be 0 always. I have tried a few other things, i dont ever remeber having this problem, i have been coding for 5 years,so am i nuts? Or should i use a delegate or something? thanks

Thread has no work.. I don't see anything inside the threadproc :S

Declaring the variable as volatile might help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.