Solved

Using BeginThread...  How do I use EndThread?  Do i need to?

Posted on 2001-08-10
4
1,000 Views
Last Modified: 2010-04-06
We are using multiple threads in our company for the first time.  We understand them enough to be dangerous. Lol.  What I need to know is if I am calling BeginThread and it kicks off my variable procedure, without calling EndThread, am I opening myself up to memoryleaks, etc.???  I watch all the threads in the debugger and it creates the thread and then magically ends.  I believe it ends when the variable procedure ends.  If I do need to call EndThread, then where do I call it at?

Here is a snipet of code.....

// ----------------------------------------------------------------------- //
//      procedure : PingContinualEquipment
//         author : jjs
//           date : 04/01
//    description : Ping the equipment in the memtable every 10 seconds
//  modifications :
// ----------------------------------------------------------------------- //
procedure TfrmPingContinually.PingContinualEquipment(Sender: TObject; Handle: Integer;
  Interval: Cardinal; ElapsedTime: Integer);
begin
   PingThreadHandle := BeginThread(nil, 0, @PingEquipmentInList, nil, 0, PingThread);
end;

PingEquipmentInList is a variable procedure, which just pings some equipment, but does nothing to end the thread.  It also doesn?t touch any variables used by any other threads or procedures, so it is kinda isolated on its own island.  No need to resync.

Rick Whitaker
Iowa Glass Depot
0
Comment
Question by:rwhitaker
  • 3
4 Comments
 
LVL 20

Accepted Solution

by:
Madshi earned 200 total points
ID: 6374375
Windows "magically" stops the thread, when your thread function is ended. It's really a joy to use.

The only one thing you have to care about is closing the thread handle you got from BeginThread ("CloseHandle(PingThreadHandle);").

Regards, Madshi.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6374377
P.S: If you have any further questions about threads, just ask. My answer just seems a bit short for 200 points, but I don't know what else to say - it's really this easy...   :-)
0
 

Author Comment

by:rwhitaker
ID: 6374491
No more questions at this time.  I was just wanting to make sure I didn't have any memory leaks that would eventually smoke our citrix/Win 2000 servers.

I am just trying to get you closer to the top of the points standings...  lol

Thanks again...

Rick
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6375199
:-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now