QueueUserWorkItem with COM in C++ -
I have a display issue where the client has hundreds of "FU" types of a special type of object in the domain of my C ++ application. Are making Each Foo frequency has its own asynchronous work queue which is obviously with its own thread, it is not on scale.
I need to share threads between working queues, and I do not want to invent the wheel again. I need to support XP, so I can not use the Vista / Win7 thread pool. The need to work on the process of each queue item is to include a com call in a multi-threaded COM apartment. The document for the XP Thread Pool says it is OK to call CohenialLeaxX () with MTA Apartment in Thread Worker Function Callback. I have written a test app and verified that it works, I run the app with 1 million iterations and without the CoInitializeEx / CoUninitialize pair in the worklist callback function. Without it CoInit * calls them and takes 35 seconds with 5 seconds. This is too much overhead for my application. Since the thread is a process per pool and in my process the third-party code runs, I'm assuming that CoInitializeEx () is not secured once per thread and CoUninitialize () never runs.
Looking at everyone, is there any way that I can use the Win32 Thread Pool? Am I missing something or is the XP thread pool too useless for the highest performing COM applications? Do I need to create my own thread-sharing system?
Have you verified what's taking too long? Which means does it call CoInitializeEx ()? You do not need to call CoInitialize once per work. You do not even say that how many threads do you create, that is, if you are running on your double core and your CPU is intensive, then there is no hope of more than 2x speed, and if your work is not The CPU is intensive so it is waiting for some resources (memory, disk, net) and speed-up, will be constrained in the same way, maybe it will get worse if locked for that resource.
If you can use Visual Studio 2010, take a look at the Parallel Pattern Library and the Asynchronous Agent's Library, there are some tools that can help write it less code.
If you can not, then you can try to keep at least one token. TLS indicates whether com has been initialized on that thread and when it is not needed Use this token's presence to bypass your calls to coilize.
Comments
Post a Comment