Threads and Memory Access Violations - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Threads and Memory Access Violations

Hello,
I have an application that creates a thread.
There are occasions when my application is
terminated because of memory access violation.
The compiler just displays the state of the
CPU when this happens and I have no idea where
in my code the access violation takes place.

The thread is created as follows:

class MyClass{
private:
DWORD dw;
HANDLE hMyThread;
... ...
public:
void Start();
void MyThreadRoutine();
... ...
};

void MyClass::Start(){
hMyThread = CreateThread(NULL, 0,
(LPTHREAD_START_ROUTINE)NonClassRoutine,
&dw, NULL);
}

MyClass::MyThreadRoutine(){
// Do something
}

//////////////////////////////////
MyClass myClass;

DWORD WINAPI NonClassRoutine(LPVOID lpVoid){
myClass.MyThreadRoutine();
return(1);
}

Is there anything wrong with my setup?

Your help is greatly appreciated.




Sign In or Register to comment.