🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Threads Threads Threads

#12422
From: Bob Gonder
Date: Wed, 03 Dec 2003 19:54
25 lines
1842 bytes
Colin Maharaj wrote:

>But this mechanisim I use, is it a good OOP approach or is there another 
>"better" way to do this.

Let's see...
You have a main thread that starts thread A, then thread B.
Thread B depends on thread A being fully initialized.

Can thread A start thread B after it has initialized?
Can thread A set a signal that the main thread waits for?

hInitEvent = CreatEvent()
start threadA
 WaitForSingleObject(hInitEvent);
CloseHandle(hInitEvent);
start threadB

Then thread A does SetEvent(hInitEvent) after it has initialized.

All this puts the "waiting" code on the O/S side which is more CPU
friendly.
If you start thread A quite a lot, then you would want to move the
CreateEvent and CloseHandle outside the loop, and use ResetEvent()
just before starting the next thread A.
Technical Details
Message-ID: <lnessvsh7gne0ari56llqhaef8tgpmcpqr@4ax.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <3FCBCCB2.C4C79E81@cablenett.net> <3fcbd0aa$3@newsgroups.borland.com> <3FCD5264.403C253A@cablenett.net>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,e26628fb95e98199
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-12-03 12:09:48 PST
From: Bob Gonder <notbg@notmindspring.invalid>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: Threads Threads Threads
Date: Wed, 03 Dec 2003 11:54:34 -0800
Organization: MindSpring Enterprises, Inc.
Reply-To: notbg@notmindspring.invalid
Message-ID: <lnessvsh7gne0ari56llqhaef8tgpmcpqr@4ax.com>
References: <3FCBCCB2.C4C79E81@cablenett.net> <3fcbd0aa$3@newsgroups.borland.com> <3FCD5264.403C253A@cablenett.net>
X-Newsreader: Forte Agent 1.93/32.576 English (American)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 67.31.165.113
X-Trace: newsgroups.borland.com 1070481276 67.31.165.113 (3 Dec 2003 11:54:36 -0700)
Lines: 27
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail