Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assertion on killing thread

Status
Not open for further replies.

discoking

Programmer
Apr 18, 2001
11
0
0
GB
I have a UI thread derived from CWinThread. I allocate the memory, call CreateThread() and it runs fine. I call AfxEndThread() to finish using an event and the thread closes down. The problem is that when it comes to the lines

if(m_bAutoDelete)
delete this;

it crashes on me. Ok so I override Delete() to stop it automatically deleting the memory (I know you can stop it auto deleting other ways) and make sure the memory is freed in the same thread that created it. I'm not sure if this is relevant? Still crashes.

No good, it's driving me mad.

Anyone know?

Greg


 
Are you using instances of CWinThread or pointers ot it? John Fill
1c.bmp


ivfmd@mail.md
 
Here's basically what the code does.

class cMyThread:public CWinThread
{
private:
HANDLE mhExitEvent;

public:
cMyThread(void);
BOOL OnIdle(LONG);
}

cMyThread::cMyThread(void)
{
mhExitEvent=CreateEvent(NULL,TRUE,FALSE,NULL);
}

BOOL OnIdle(LONG)
{
CWinThread::OnIdle();

if(WaitForSingleObject(mhExitEvent,0)==WAIT_TIMEOUT)
{
//Processing.
}
else
AfxEndThread(0);
}

main()
{
pThread=new cMyThread;
assert(pThread);

pThread->CreateThread();

//Do Processing.

//Finished so exit thread.
SetEvent(pThread->getExitEvent());

//Cleanup.
}

It initialises fine and runs (I know I've missed bits out) but what about the memory assertion?

Any ideas?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top