In Microsoft Visual C ++, I can call CreateThread () to create a thread by running a function with one parameter void *. I pass a pointer to the structure as this parameter, and I see that many others are doing this.
My question is: if I pass a pointer to my structure, how do I know if structure elements were actually written to memory before calling CreateThread ()? Is there any guarantee that they will not be simply cached? For instance:
struct bigapple { string color; int count; } apple;
apple.count = 1;
apple.color = "red";
hThread = CreateThread( NULL, 0, myfunction, &apple, 0, NULL );
DWORD WINAPI myfunction( void *param )
{
struct bigapple *myapple = (struct bigapple *)param;
cout << "Apple count: " << myapple->count << endl;
}
, , Windows - , , , , , - . , ++ , , " ", , - . , , & apple CreateThread(), , apple.