Re: MTA with Thread Pool API

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



What's wrong with NOT calling CoUninitialize?

--
Vladimir


"Sarge" <Sarge@xxxxxxxxxxxxxxxxx> wrote in message
news:%23y7qnokiGHA.4080@xxxxxxxxxxxxxxxxxxxxxxx

"Scherbina Vladimir" <vladimir.scherbina@xxxxxxxxxxxx> wrote in message
news:%23QLYA2jiGHA.1936@xxxxxxxxxxxxxxxxxxxxxxx
Hello, Sarge.

<Sarge@xxxxxxxxxxxxxxxxx> wrote in message
news:efZPZUZiGHA.1508@xxxxxxxxxxxxxxxxxxxxxxx
I have a C/C++ multi-threaded socket server app that uses OLE DB for it's
SQL activity. The app uses a completion port for socket I/O, but doesn't
properly implement connection pooling with OLE DB. Each thread of the
process holds on to it's own connection object (IDBInitialize), which I
know is wrong.

So I'm rewriting this app to maintain one IDataInitialize object, and
create the IDBInitialize objects on the fly, using the same connection
string. Hopefully, this won't add too much overhead, but it's what the
Microsoft technical article says to do for proper connection pooling.

Anyway, my question is related to CoInitializeEx(MTA) / CoUninitialize()
in regards to the thread pool API. I really like using this API -
QueueUserWorkItem(), BindIoCompletionCallback(),
RegisterWaitForSingleObject(), etc.

The problem is that Windows manages these threads, so I don't have the
opportunity to call CoInitializeEx / CoUninitialize. Using Thread Local
Storage, I can flag whether or not the thread has called CoInitializeEx,
but I still have no opportunity to call CoUninitialize.

The SDK is very clear that you must call the CoInit functions once per
thread that uses COM. I thought about moving all the code into a DLL,
and using THREAD_ATTACH and THREAD_DETACH, but the SDK also says *not*
to call the CoInit functions from DLLMain().

Does this mean that I'm stuck with my own completion ports, or is there
some way that I can use the thread pool API?

Thanks for your time.

--Sarge



I may suggest to use own thread pool and control all CoInitialize(),
CoUnitialize() calls, or miss the call of CoUninitialize() when your
worker threads are done - I guess this will be when your application
terminates so at this point usless think (but remember that this is a
good style) about resources.

--
Vladimir


Vladimir, I was afraid of that. I can do my own thread pool and handle
the CoInit functions from my own worker threads. Since I'm writing those
threads, it's easy to issue CoInitializeEx at the top and CoUninitialize
at the bottom.

I sure will miss the convenience of the thread pool API. :-(

--Sarge



.



Relevant Pages

  • Re: MTA with Thread Pool API
    ... Microsoft technical article says to do for proper connection pooling. ... CoUninitialize() in regards to the thread pool API. ... CoInitializeEx, but I still have no opportunity to call CoUninitialize. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: ADO in multithreaded: Application Verifier (with WinDbg) gives "Invalid Handle" at the end of my
    ... Invalid Handle doesn't appear at CoUninitialize() function on this ... CoInitializeEx isn't called on any other thread from this application. ... Sorry if this sounds like a stupid suggestion, but did you switch ADO to ... If the database you are connecting to has a driver that support connection ...
    (microsoft.public.data.ado)
  • Re: MTA with Thread Pool API
    ... Microsoft technical article says to do for proper connection pooling. ... my question is related to CoInitializeEx/ CoUninitialize() ... Storage, I can flag whether or not the thread has called CoInitializeEx, ... some way that I can use the thread pool API? ...
    (microsoft.public.win32.programmer.kernel)
  • COM with Thread Pool API
    ... I would like to use COM and also use the Thread Pool API ... The problem is that Windows manages creating and destroying the Thread Pool ... CoUninitialize. ... thread has called CoInitializeEx, but I still have no opportunity to call ...
    (microsoft.public.vc.atl)
  • Re: TAPI sample in VC++ using MFC
    ... It seems as though I can put the CoInitializeEx just about anywhere, ... matter where I put the CoUninitialize I get the crash. ... >> One problem remains in the sample code. ... > destination number and the destination type in my sample. ...
    (microsoft.public.win32.programmer.tapi)