Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1138
  • Last Modified:

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

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
rwhitaker
Asked:
rwhitaker
  • 3
1 Solution
 
MadshiCommented:
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
 
MadshiCommented:
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
 
rwhitakerAuthor Commented:
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
 
MadshiCommented:
:-)
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now