Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

DLL and TThread

108 views
Skip to first unread message

Mark Lauter

unread,
May 2, 2000, 3:00:00 AM5/2/00
to
I'm having problems with a TThread and a DLL. I terminate and free the thread
from an ExitProc because the DLL detaches threads long before any finalization
code is called. The problem is that if I load and free the dll "manually" using
LoadLibrary & FreeLinrary the ExitProc never gets called so the threads don't
get terminated. Well I fixed that problem by checking to see if the ExitProc
ever got executed, then execute it manually if it hasn't.
Now I've gotten the thread to appear to terminate and the DLL appears to get
freed, but in a couple seconds I get an access violation in a second thread that
I can't trace into.

I have a test app that demonstrates the problem for anyone who wants to try to
tackle this sticky problem.

Thanks,

--

Mark Lauter
Senior Software Engineer
--------------------------
Emaigisoft
http://www.quicksuite.com/
--------------------------
The apologists are the ones who
defend the computer because it can
accomplish a task that was heretofor
impossibly difficult. They point to the
bear and exclaim, "Look, it's dancing!"

Peter Below (TeamB)

unread,
May 2, 2000, 3:00:00 AM5/2/00
to
In article <390ecece@dnews>, Mark Lauter wrote:
> I'm having problems with a TThread and a DLL. I terminate and free the thread
> from an ExitProc because the DLL detaches threads long before any finalization
> code is called.
>

ExitProc? YOu should use DLLProc, not ExitProc.

Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitly requested!


Mark Lauter

unread,
May 2, 2000, 3:00:00 AM5/2/00
to
Yeah, I'm trying that too. Here is a sample. I removed the logging to make
this more readable.

code looks like this......

The timer thread executes the OnTerminate event but never gets past the
WaitFor(). I've tried setting the threads FreeOnTerminate property to true,
I've tried not freeing the thread, I've tried not terminating the thread, I've
tried terminating but not WaitingFor. No matter what I do I get an access
violation a second or two after the call to FreeLibrary, that is IF I don't
WaitFor(), otherwise I get blocked at the WaitFor.

Thanks in advance for anymore help.

procedure CleanUp;
var
i : integer;
c : integer;
timer : TTimerThread;
begin
c := TimerList.Count - 1;
for i := 0 to c do
begin
timer := TimerList.Items[i];
timer.Terminate();
timer.WaitFor();
timer.Free();
end;
TimerList.Free();
TimerList := nil;
end;

procedure DllEntryProc(Reason : integer);
begin
case Reason of
DLL_PROCESS_DETACH :
begin
ALog.Add('PROCESS_DETACH', []);
CleanUp();
end;
DLL_PROCESS_ATTACH : ALog.Add('PROCESS_ATTACH', []);
DLL_THREAD_ATTACH : ALog.Add('THREAD_ATTACH', []);
DLL_THREAD_DETACH : ALog.Add('THREAD_DETACH', []);
end;
end;


--

Mark Lauter
Senior Software Engineer
--------------------------
Emaigisoft
http://www.quicksuite.com/
--------------------------
The apologists are the ones who
defend the computer because it can
accomplish a task that was heretofor
impossibly difficult. They point to the
bear and exclaim, "Look, it's dancing!"


"Peter Below (TeamB)" <10011...@compuXXserve.com> wrote in message
news:VA.00004fa...@antispam.compuserve.com...

Jeff Overcash (TeamB)

unread,
May 2, 2000, 3:00:00 AM5/2/00
to
WaitFor will not work when Dll's are being freed through FreeLibrary. Nothing
but the simplest of things will work (mutexes stop firing and other more
advanced items stop working). This is a Windows limitation. Your best bet is
to export your Cleanup procedure and call it right before you can FreeLibrary.


--
Jeff Overcash (TeamB)
(Please do not email me directly unless asked. Thank You)
Have you ever met a lady screaming angst potential?
Have you ever dreamed of romance no matter how experimental?
Have you ever felt an alien drifting back into your hometown?
Did you think you were buying safety when you bought that piece of ground?
(Fish)

Mark Lauter

unread,
May 3, 2000, 3:00:00 AM5/3/00
to
That will be hard because the REAL DLL is getting loaded and freed from IIS.
Its an ISAPI app. You have provided enough information that I think I can work
it out though.

Thanks,
--

Mark Lauter
Senior Software Engineer
--------------------------
Emaigisoft
http://www.quicksuite.com/
--------------------------
The apologists are the ones who
defend the computer because it can
accomplish a task that was heretofor
impossibly difficult. They point to the
bear and exclaim, "Look, it's dancing!"


"Jeff Overcash (TeamB)" <over...@onramp.net> wrote in message
news:390F766F...@onramp.net...

Mark Lauter

unread,
May 3, 2000, 3:00:00 AM5/3/00
to
We're gonna move our threads out to external services. The ISAPI app already
has WAY too much responsibility. I've decided that this thread issue was just a
symptom of a larger design problem. The other good news is, now I'm the local
thread/DLL expert. <grin>
0 new messages