Gracefully shutting down a thread in a DLL
- From: "Bruce." <noone@xxxxxxxxxxx>
- Date: Mon, 17 Mar 2008 18:30:35 -0500
XP/Server 2003.
We have a DLL, very old, and being used by hundreds of applications. I'm in
the process of adding a maintenance thread (the first) to that DLL. It has
to be done in a way that won't require me changing hundreds of other
programs. Many of these are customer programs outside of my control.
I wrote the thread and am starting it when the DllMain is called with
DLL_PROCESS_ATTACH. So far so good.
The thread starts, runs, and everything works, until it's time to shut down.
I can't get the thread to gracefully exit. When the host exe exits, Windows
calls DllMain with DLL_PROCESS_DETACH. In that I set a terminate flag for
the thread to see, but thread in the dll doesn't run long enough to see it,
so it never completes, and never cleans up.
In researching this on the web, it turns out that DLL_PROCESS_DETACH isn't
called until after all process threads have already been halted,
ungracefully if necessary. That makes it sound impossible to signal the
thread at that time to have it exit.
So is there any good way to get the thread in a dll to gracefully exit
without modifying the exe's that use the dll?
Thanks for any help.
Bruce.
.
- Follow-Ups:
- Re: Gracefully shutting down a thread in a DLL
- From: roger . orr
- Re: Gracefully shutting down a thread in a DLL
- From: Ivan Brugiolo [MSFT]
- Re: Gracefully shutting down a thread in a DLL
- Prev by Date: Re: GET KPROCESS from user mode
- Next by Date: Re: Advisory file locking support?
- Previous by thread: No Dependencies in Service applet
- Next by thread: Re: Gracefully shutting down a thread in a DLL
- Index(es):
Relevant Pages
|