tags:

views:

61

answers:

3
            int NM_Generator = 1; 

            //Aray to store thread handles 
            HANDLE Array_Of_Thread_Handles[1];

            //variable to hold handle of North pulse
            HANDLE Handle_Of_NM_Generator = 0; 

            //Create NM_Generator Thread
            Handle_Of_NM_Generator = CreateThread( NULL, 0, NMGenerator, &dDifference, 0, NULL);  
            if ( Handle_Of_NM_Generator == NULL)   ExitProcess(NM_Generator); 

i want to pass a parameter double value in it how can i do so?

A: 

ok i find it

        //Create NM_Generator Thread
        Handle_Of_NM_Generator = CreateThread( NULL, 0, NMGenerator, &dDifference, 0, NULL);  
        if ( Handle_Of_NM_Generator == NULL)   ExitProcess(NM_Generator); 


 //dDifference is the thread parameter 
moon
A: 

You are already passing the parameter with "&dDifference".

Check this example on how to create a thread.

Jujjuru
+2  A: 

CreateThread allows you to pass in a single parameter of type void * and the thread procedure is called with the parameter.

If you want to pass an argument of type T where sizeof(T) <= sizeof(void *), you can simply cast your argument to a void * in the call to CreateThread and cast it back to your type in your thread procedure.

But if sizeof(T) > sizeof(void *) you are going to need to create a structure that will hold your arguments. You will then pass a pointer to the CreateThread call (as a void *).

When passing a pointer to a structure, you will need to make sure it has an appropriate lifetime. The easiest way to do this is by allocating the structure on the heap before calling CreateThread and then freeing the memory inside your thread procedure.

R Samuel Klatchko