I have an weird problem with multithreading. I implemented a simple worker thread. I pass to it two pointers to two variables. One is an integer, and the second is a bool. Both are pointers to private data members in doc. Now, I use the bool as a way to "stop" the worker thread at any given moment. For example, if the use wanted to stop the process for any reasons, the user can click the "stop" button, which would then set the bool variable passed that was passed to the worker thread to false.
Inside the worker thread, I call a function and pass it a pointer to the bool variable. The program compiles without a problem; however, it crashes at the point where it checks the status of the pointer to the bool variable. I have tried different technique including passing in a pointer to a pointer, etc. None has worked. Here is a summary.
bool *pBoolVariable = ptp->pBVariable;
// X is a pointer to a class object
classX *cX = ptp->X;
// passing a pointer to a bool variable
The problem will crash when it checks the status of pBoolVariable inside myFunction.
I am not sure if I need to change the way I am passing the bool variable to the function. I have tried passing in a reference, but the program crashs the same way. The algorithm above works only if pBoolVariable is not passed into myFunction. Weird.
Please post if you see a possible problem.