🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: WaitForMultipleObjects in TThread

#11607
From: Charlie Page
Date: Sat, 31 Jan 2004 21:10
16 lines
1980 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: <401c19bd$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!c03.atl99!news.usenetserver.com!news-hog.berkeley.edu!ucberkeley!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!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:15:40 PST
Date: Sat, 31 Jan 2004 16:10:24 -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.106.36
Message-ID: <401c19bd$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1075583421 64.252.106.36 (31 Jan 2004 13:10:21 -0800)
Lines: 16
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!c03.atl99!news.usenetserver.com!news-hog.berkeley.edu!ucberkeley!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail