I am using MS Visual C++ 6.0.
I am creating a WebService wrapper around a legacy VB 6.0 application.
The VB 6.0 application is slow to startup and sign on. To minimize this overhead, I am attempting to create a pool of objects from which my worker threads can retrieve objects.
I have a main thread that creates an instance of my PoolManager class, which in turn creates a pool of COM objects. My PoolManager has a method called getConnection which can locate an available COM object and return a pointer to its interface (actually it returns a pointer to an IStream created from CoMarshalInterThreadInterfaceInStream.)
My worker threads get created when clients connect through the WebService. Each thread needs to call the PoolManagers getConnection method to get the address of the IStream so it can perform a CoGetInterfaceAndReleaseStream to get a pointer to the COM interface.
Here is where I am confused:
a) The PoolManager is on thread 1, thus the COM objects were created on thread 1.
b) The Worker is, for example, on thread 2.
c) The Worker calls PoolManager.getConnecction which executes on thread 2. (assume the code is protected from concurrency issues)
d) The method getConnection, running on thread 2, calls CoMarshalInterThreadInterfaceInStream and returns the IStream pointer.
e) The worker thread continues and calls CoGetInterfaceAndReleaseStream to get an interface pointer.
1) Is it OK that CoMarshalInterThreadInterfaceInStream is called on Thread 2?
2) If NO, any recommendations on how to avoid this?