🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: WaitForMultipleObjects in TThread

#11622
From: Kristoffer Persson
Date: Mon, 02 Feb 2004 08:15
28 lines
2304 bytes
"Charlie Page" <lissom@hotmail.com> wrote in message
news:401c18c1@newsgroups.borland.com...
> 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

This looks like a good idea, but my threads usually wait in a GetMessage
call. Maybe a combination would be best, where I set an event and send a
message to the threads. Then it would work for both GetMessage and
WaitForMultipleObjects.

- Kristoffer -

PS. Charlie: Do you have a nice way to find out if a thread is dead/freezed
in your thread holder class?
Technical Details
Message-ID: <401e070a@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!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> <401c18c1@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-02-02 00:39:31 PST
From: "Kristoffer Persson" <no@email>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <40191ff7$1@newsgroups.borland.com> <1075389099.199618@post.sympatec.net> <401a0744$1@newsgroups.borland.com> <401c18c1@newsgroups.borland.com>
Subject: Re: WaitForMultipleObjects in TThread
Date: Mon, 2 Feb 2004 09:15:32 +0100
Lines: 30
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 193.15.214.81
Message-ID: <401e070a@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1075709706 193.15.214.81 (2 Feb 2004 00:15:06 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail