Click to See Complete Forum and Search --> : Threads and DLL


sgonepudi
March 6th, 2006, 08:47 AM
I have a DLL. It exports only one function.

Example Code:

extern "C" void Test()
{
abc ob1 = new abc();
ob1->xyz();
delete ob1;
}


I have created a dialog box client with multiple threads.

Each thread, checks whether the DLL loaded or not, if not loads the dll and calls the exported function.

Here my question is, in the exported function I am allocating memory for abc class. Each thread was accessing this exported function, means each thread allocates memory for abc class in his own address space or not? If it is right means every thread having different abc class instance.

i think here thread synchronization is not required becuase each thread having different instances.

If any body knows about this please explain how dll behaves in multithread client exe application.

Arjay
March 6th, 2006, 09:38 AM
Each thread was accessing this exported function, means each thread allocates memory for abc class in his own address space or not? If it is right means every thread having different abc class instance.Each time your thread calls the function a new instance of the class is created - that is correct.


i think here thread synchronization is not required becuase each thread having different instances.
You are correct again.

Synchronization is only required when you are sharing data between a thread (or process). In the case presented here, there is no data sharing going on (unless the abc class has static data and/or global data); therefore, no synchronization is required.

Arjay