Article View: borland.public.cppbuilder.nativeapi
Article #16175Re: race conditions!!
From: Michael Kelly
Date: Thu, 29 May 2003 17:19
Date: Thu, 29 May 2003 17:19
35 lines
2501 bytes
2501 bytes
On Thu, 29 May 2003 14:39:14 +0200, "Tharun Pillay" <tharun@webmail.co.za>
wrote:
>My worker thread is responsible for pooling, queues, etc. and my
>deallocation thread frees memory when the threads in the pool have
>terminated (it does this by checking GetExitCodeThread). I've managed to
>solve it by setting a flag for when the deallocation thread can free, though
>this seems a bit prone to disaster. Especially since the worker threads
>objects are derived from a base class and setting the flag is the classes
>responsibility.
I would take a look at some code that manages a thread pool
'cause it can be kind of tricky. Generally memory should be
freed by the same thread that allocates it(unless it's some
heap allocation that has a thread id in the call to deallocate
etc. or you are destroying objects created in the manager
thread or something else that makes sense.)
I think it is best to get some separation or "loose coupling"
between the thread you are going to kill/free and the pool
manager. So some type of Kernel Object is probably a
good idea. You might take a look at some of the C++
programming sites for thread pool algorithms or patterns.
Try MSDN and http://www.windevnet.com/
Also if you know Delphi you might see something good
on Torry's site. I use a Delphi Component TMultiTasker
for multi-thread stuff in Delphi. Looking at the source
might be helpful esp. if you use VCL thread objects.
--
"I don't want to belong to any club that would have me as a member."
-- Groucho Marx
Technical Details
Message-ID:
<dmfcdvgetuqsghoibfnkuumjhfprcb579o@4ax.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!small1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<3ed5feaf@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,920bad3f7b14165b X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-05-29 10:20:03 PST From: Michael Kelly <mkelly2002@adelphia.net> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: race conditions!! Date: Thu, 29 May 2003 13:19:02 -0400 Message-ID: <dmfcdvgetuqsghoibfnkuumjhfprcb579o@4ax.com> References: <3ed5feaf@newsgroups.borland.com> X-Newsreader: Forte Agent 1.92/32.572 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 24.51.218.66 X-Trace: newsgroups.borland.com 1054228726 24.51.218.66 (29 May 2003 10:18:46 -0700) Lines: 35 Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!small1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail