Just wondering if anyone could advise me on this problem I have. I have a main thread which creates an instance of one of my classes, call it class A. The main thread then creates another thread and uses a method from class A as the defined function to be executed on the thread.
After which, the main thread starts polling for events to be signaled from the second thread (the one from class A). Now when I get an event signaled, this means that there is a data structure ready for me to read from the main thread. The data structure is a public member of class A. The problem I am fearful of, is that the main thread could try reading the data structure and the second thread is also trying to refill the data structure at the same time.
I could have two versions of the same structure within class a, one public and one private, and the main thread just reads the public one. Nevertheless, the same problem could occur when
class A tries to do a memcpy from the private to public member of the structure, and my main thread tries to read the public structure whilst the 2nd thread is doing the memcpy.
When should I use EnterCriticalSection? Should I use it within class a when it is doing the memcpy or should I do it within my main thread when I want to read the data structure.
Any advise on this would be helpful. Thanks.