Multithread heap assertion failure(Continued)



I create a win32 console project with mfc support(shared dll) using
VS2003, and add the following source file to my project.

When run, there is "debug assertion failure" error around here in
thrdcore.cpp:
--------------
// check to make sure the VTable pointer is valid
ASSERT(sizeof(CObject) == sizeof(void*));
if (!AfxIsValidAddress(*(void**)pOb, sizeof(void*), FALSE))
{
TRACE(traceAppMsg, 0, "ASSERT_VALID fails with illegal vtable
pointer.\n");
if (AfxAssertFailedLine(lpszFileName, nLine))
AfxDebugBreak();
return; // quick escape
}
--------------
The exact position is at "AfxDebugBreak()" in the deepest place.


Having programmed for years, I am still new to multithreaded
programming.
I would usually refer to docs when I have something to check.
But, as for multithread programming, I don't know what is going
wrong.
And I don't know which part of mannual should I read.
I have to ask you for help.

*Any help will be appreciated. Thanks in advance.*

Here is the call stack:
---------------
mfc71d.dll!AfxAssertValidObject(const CObject * pOb=0x00a555f4, const
char * lpszFileName=0x7c15264c, int nLine=375) 行92 C++
mfc71d.dll!AfxEndThread(unsigned int nExitCode=1, int bDelete=1) 行
376 C++
mfc71d.dll!_AfxThreadEntry(void * pParam=0x0013fd98) 行134 C++
msvcr71d.dll!_threadstartex(void * ptd=0x00a55810) 行241 + 0xd C
kernel32.dll!7c80b683()


And Here is the source file:
---------------
#include <afx.h>
#include <afxmt.h>
#include <afxwin.h> // MFC core and standard components
#include <windows.h>

#include <iostream>
using namespace std;

class CTestThread: public CWinThread{
public:
long timeout;

CTestThread(){}
virtual ~CTestThread(){}

int Run(){
cout << "run..." << endl;
Sleep(timeout);
return 1;
}

BOOL InitInstance(){
cout << "init..." << endl;
return TRUE;
}

int ExitInstance(){
cout << "exit inst..." << endl;
return 0;
}
};

int main(){
int nWorkerNum = 2;
CTestThread * m_pThread = new CTestThread[nWorkerNum];
HANDLE * m_pThreadHandle = new HANDLE[nWorkerNum];
for(int i = 0; i < nWorkerNum; i ++){
m_pThread[i].CreateThread();
m_pThread[i].m_bAutoDelete = FALSE;
m_pThreadHandle[i] = m_pThread[i].m_hThread;
}
m_pThread[0].timeout = 1;
m_pThread[1].timeout = 3000;
WaitForMultipleObjects(nWorkerNum, m_pThreadHandle, FALSE, INFINITE);
cout << "here" << endl; cout.flush();
clock_t s = clock();
WaitForMultipleObjects(nWorkerNum, m_pThreadHandle, TRUE, 2500);
clock_t e = clock();
cout << "####" << (e - s) << endl;
cout << "there" << endl; cout.flush();

for(int i = 0; i < nWorkerNum; i ++){
m_pThread[i].ExitInstance();
}

delete [] m_pThreadHandle;
delete [] m_pThread;

cout << "Press c to conitnue..." << endl;
cout.flush();
char c; cin >> c;
}

.



Relevant Pages

  • Re: Portability: Harmony between PC and microcontroller
    ... int is the natural integer type for the system. ... You are, perhaps unintentionally, paraphrasing the standard in a way ... One of the things that you might not realize is that the C programming ... In the real world, most embedded systems have more complex jobs to do, ...
    (comp.lang.c)
  • Re: What will be the next MAJOR programming language for commercial use?
    ... Variants can be considered as such a common OO pattern that it is worth ... Int of int ... As lists are built-in, they can be decomposed in a pattern just as they are ... features found in other state-of-the-art programming languages. ...
    (comp.lang.misc)
  • Re: Bug/Gross InEfficiency in HeathFields fgetline program
    ... Maybe this is true in the sort of programming you do, ... you are storing a list of amounts of money as integers. ... int average ... the array, rounded towards zero. ...
    (comp.lang.c)
  • Re: beginner with programming, how to learn to debug and few C general questions
    ... I am first an accountant and decided to take on programming a few ... I have mainly been programming under Windows Xp DJGPP Dolorie... ... int main ... If you fix all of the above problems, it might fix whatever the issue ...
    (comp.lang.c)
  • Re: Lisp version of a Cism
    ... > int main{ ... This may be nice code for a newbie textbook on C programming, ... that include any kind of cross-platform portability, ... When we compare it to Lisp, we find that all the high level stuff is ...
    (comp.lang.lisp)