Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   basic threading help (http://www.go4expert.com/forums/basic-threading-help-t28142/)

Daedalus031 6Apr2012 06:16

basic threading help
 
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

xpi0t0s 17Apr2012 16:02

Re: basic threading help
 
args is a pointer, so you must use args->id, not args.id.


All times are GMT +5.5. The time now is 01:05.