🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #11606

Re: WaitForMultipleObjects in TThread

#11606
From: Charlie Page
Date: Sat, 31 Jan 2004 21:06
16 lines
1962 bytes
If you have a lot of threads that you want to terminate when the program 
  terminates this is the method that i use.
1)Create an event (MyTerminateEvent).
2)When a thread waits, always use WaitForMultipleObjects and include the 
MyTerminateEvent.
3)In the main form's destructor (the the projects .cpp file, if 
necessary) signal the event and then wait for the threads to terminate. 
  MyThread.WaitFor for a TThreadObject.
(I have a thread holder class that does this, and you will need to use a 
similar construct if you create a lot of nameless threads.  There is a 
counter that the threads increment/decrement on 
creation/end_of_processing[threads memory may not be deallocated at end 
of CPU time].  When the counter reaches zero, all threads have quit and 
the program can too.)

charlie
Technical Details
Message-ID: <401c18c1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <40191ff7$1@newsgroups.borland.com> <1075389099.199618@post.sympatec.net> <401a0744$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,2e632a3799f22e8b
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2004-01-31 13:09:35 PST
Date: Sat, 31 Jan 2004 16:06:11 -0500
From: Charlie Page <lissom@hotmail.com>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6b) Gecko/20031205 Thunderbird/0.4
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: WaitForMultipleObjects in TThread
References: <40191ff7$1@newsgroups.borland.com> <1075389099.199618@post.sympatec.net> <401a0744$1@newsgroups.borland.com>
In-Reply-To: <401a0744$1@newsgroups.borland.com>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 64.252.101.250
Message-ID: <401c18c1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1075583169 64.252.101.250 (31 Jan 2004 13:06:09 -0800)
Lines: 16
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail