Subj : Multi-Thread and memory allocation error (or bug in 5.02). To : borland.public.cpp.borlandcpp From : "Martin Catney" Date : Fri Aug 29 2003 06:10 pm I am experience some problems with Borland 5.02 with multitheads and memory allocation and deallocation. The same code on Borland Builder 6 appears to work fine. I have included an example program which creates multiple instances of the same class then deletes them. The class constructor creates a new thread and allocates a large block of memory while the destructor deallocates the memory and terminates the thread. I get an access violation at 0x634b5e: read of address 0x4cdc058 when I run the example. This corresponds to the line delete[] array; in the class destructor. If the creation and termination of the threads is removed the example runs fine. Does anyone spot an obvious error in my example or is this a bug in the Run-Time Library? Regards Martin #include #include //#include //#define ASIZE 159727 #define ASIZE 159727 void _USERENTRY ThreadFunction(HANDLE hEvent) { WaitForSingleObject(hEvent, INFINITE); } class TVMImageList { public: TVMImageList(unsigned long noImages, unsigned long size); ~TVMImageList(); public: unsigned long mSize; unsigned long mLength; int* array; int** thearray; HANDLE hEvent; HANDLE mThread; unsigned long mThreadID; }; TVMImageList::TVMImageList(unsigned long noImages, unsigned long size) :mSize(size), mLength(noImages) { hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); mThread = (HANDLE)_beginthreadNT( ThreadFunction, // pointer to thread function 4096, // stack size hEvent, // argument for new thread NULL, 0, &mThreadID ); SetThreadPriority((void*)mThread,THREAD_PRIORITY_NORMAL); thearray = new int*[mLength]; for (int i =0; i