basic threading help

Daedalus031's Avatar, Join Date: Apr 2012
Newbie Member
I am very new to threading and am having a small problem i just can't find the solution for. I am wanting to print out the values of args.id and args.delay inside the mythread function. however i am getting the error error "C2228: left of '.id' must have class/struct/union".
Code:
struct ThreadArgs{
  int id;
  int delay;
}args ;
		


void main(){
		unsigned __stdcall mythread(void *data);
		unsigned ThreadId;

		int x = 5;
		args.id = 2;
		args.delay = 3;

		HANDLE hThread = (HANDLE)_beginthreadex(NULL, 0, mythread, &args, 0, &ThreadId);
		WaitForSingleObject(hThread, INFINITE);
		//Sleep(2000);

}

unsigned __stdcall mythread(void *data)
{
		Sleep(1000);


		ThreadArgs *args = (ThreadArgs *) data;
		cout<<args.id<<endl;

		cout<<"hello world"<<endl;
		return 0;
}
Thanks in advance for any help

Last edited by shabbir; 6Apr2012 at 10:20.. Reason: Code blocks
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
args is a pointer, so you must use args->id, not args.id.