sgonepudi
February 28th, 2006, 01:24 PM
I have created a Multithread DLL. I used the following design for creating multithread DLL.
1) Created Queue based Thread Pool class
2) Created a User class (Ex: CPoolItem) which contains the some logic.
3) Exported one function for creating Thread Pool (Ex: CreateThreadPool).
4) Exported one function for deleting Thread Pool (Ex: DeleteThreadPool).
5) Exported one function. it takes 2 numbers and returns the result.
extern "C" long __stdcall Add(int a,int b)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
HMODULE hMod = ::GetModuleHandle( "Test.dll" );
ASSERT( hMod );
AfxSetResourceHandle( hMod );
long LResult = 0L;
CPoolItem *pPoolItme = new CPoolItem(a,b); //User class
theApp.m_Pool.AddClientReqObj(pPoolItme);//Inserting the request to the Thread Pool queue.
if(theApp.m_Pool.ProcessClientRequest(pPoolItme)) // Waiting for the completion of Client Request
LResult = pPoolItme->rtnResultValue(); //Getting the result
delete pPoolItme;//Deleting the object
return LResult;// returning the result
}
I want to test the above dll with multiple requests at a time, for that I created a Dialog Based Application. In that application I have loaded the above DLL and created the Thread Pool (DLL Thread Pool) in OnInitDailog() function and deleted the Thread Pool and Unloaded the DLL in OnClose() function.
I have placed one button in the Dialog box. In the button click event, created 50 threads and each thread calls the Add function (which is present in the DLL) with different data.
Everything is working fine. I clicked the button continuously for testing. There is no problem.
Here I have some questions:
1) Is this right design for creating MultiThread DLL?
2) In this design ThreadPoc takes the PoolItem object from the Queue and it calls the Add member function of PoolItem.
I have created CDatabase object, open the object and just closed the object in Add member function of PoolItem class.
At this time my DLL is giving following exception.
HEAP: Free Heap block 128eee0 modified at 128ef08 after it was freed
But this exception is coming some times only. It is coming in the below statement.
CPoolItem *pPoolItme = new CPoolItem(a,b);
3) I have created CDatabase object as a member variable. I opened and closed the database connection in the Add member function. In this situation OpenEx function is not allowing to connect the database.
It is giving Access Violation Exception.
If any body knows about this please let me know the reason.
1) Created Queue based Thread Pool class
2) Created a User class (Ex: CPoolItem) which contains the some logic.
3) Exported one function for creating Thread Pool (Ex: CreateThreadPool).
4) Exported one function for deleting Thread Pool (Ex: DeleteThreadPool).
5) Exported one function. it takes 2 numbers and returns the result.
extern "C" long __stdcall Add(int a,int b)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
HMODULE hMod = ::GetModuleHandle( "Test.dll" );
ASSERT( hMod );
AfxSetResourceHandle( hMod );
long LResult = 0L;
CPoolItem *pPoolItme = new CPoolItem(a,b); //User class
theApp.m_Pool.AddClientReqObj(pPoolItme);//Inserting the request to the Thread Pool queue.
if(theApp.m_Pool.ProcessClientRequest(pPoolItme)) // Waiting for the completion of Client Request
LResult = pPoolItme->rtnResultValue(); //Getting the result
delete pPoolItme;//Deleting the object
return LResult;// returning the result
}
I want to test the above dll with multiple requests at a time, for that I created a Dialog Based Application. In that application I have loaded the above DLL and created the Thread Pool (DLL Thread Pool) in OnInitDailog() function and deleted the Thread Pool and Unloaded the DLL in OnClose() function.
I have placed one button in the Dialog box. In the button click event, created 50 threads and each thread calls the Add function (which is present in the DLL) with different data.
Everything is working fine. I clicked the button continuously for testing. There is no problem.
Here I have some questions:
1) Is this right design for creating MultiThread DLL?
2) In this design ThreadPoc takes the PoolItem object from the Queue and it calls the Add member function of PoolItem.
I have created CDatabase object, open the object and just closed the object in Add member function of PoolItem class.
At this time my DLL is giving following exception.
HEAP: Free Heap block 128eee0 modified at 128ef08 after it was freed
But this exception is coming some times only. It is coming in the below statement.
CPoolItem *pPoolItme = new CPoolItem(a,b);
3) I have created CDatabase object as a member variable. I opened and closed the database connection in the Add member function. In this situation OpenEx function is not allowing to connect the database.
It is giving Access Violation Exception.
If any body knows about this please let me know the reason.