Since I'm not sure whether to put this in the C++ or Windows section I'm just going to dump it here.
I have a question regarding classes and threads. Say you have a class which has two static member functions which serve as the entry points for two different threads:
Now, let's say these two threads are created and started in another member function of the class (which is not static).Code:
static DWORD WINAPI Thread1(LPVOID pClassInstance);
static DWORD WINAPI Thread2(LPVOID pClassInstance);
Each thread receives a pointer to the instance of the class that created them so they can use private resources such as member variables and functions.
My question then goes as follows:
Imagine both threads reading data from somewhere. This data is manipulated by the same member function. So, what happens if say Thread1 calls this function, gets suspended by the OS halfway through and Thread2 then calls this same function. I mean, is there a potential danger here that they might share data (like Thread2 overwriting something Thread1 did)?
I believe local variables exist in each of the threads' own address space, but I just want to be absolutely sure! But what about static local variables? Is it then the same memory both threads access?