I have a native Visual C ++ NT service. When a service starts, its thread calls CoInitialize(), which attaches the thread to the STA â the service thread uses MSXML through COM interfaces.
When a service receives SERVICE_CONTROL_STOP, it sends a message to the message queue, and then receives this message and the handler is called OnStop(). A handler cleans the material and calls CoUnitialize(). Most of the time it works fine, but from time to time the last call freezes. I cannot stably reproduce this behavior.
For a while I searched Google and found the following likely explanations:
The first is unlikely - the code using MSXML is well tested and analyzed, and it uses smart pointers to control the life cycle of objects, so leakage of objects is really unlikely.
The second option does not look like the probable cause. I join the STA and do not call these functions again.
The third one looks more or less likely. While the thread is processing the message, it no longer starts the message loop - it is already inside the loop. I guess that could be the reason.
Is the latter a likely cause of this problem? What other reasons should I consider? How to solve this problem easily?
source
share