🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Converting existing non-threaded app to threaded

#6185
From: Oliver Rutsch
Date: Wed, 01 Jun 2005 15:31
38 lines
2926 bytes
Hi, Matt.

> I have a fairly large C++ Builder 6 project I would like to make threaded. 
> Apart from the main class which handles most of the UI, I have two other 
> major C++ classes that are just about pure C++ with no VCL. I would like to 
> convert these to threaded classes. This is a simulation of artificial life. 
> One of the classes is instantiated anything up to one hundred times [the 
> living animals] and the other up to three or four hundred [the food]. This 
> would mean I would have upwards of 500 threads, is this possibly under 
> Windows XP?
> 

500? I think it is possible but it makes no sense. Why must every object 
have it's own thread? Why not only a few (e.g. num of CPU's) threads who 
manage theses objects? Too many threads will loose a lot of time with OS 
switching between the threads.


> access. The way I intend to use them is have each thread start suspended and 
> use a timer on my main form to trigger the resuming of each thread. They go 
> off and do their thing, and suspend themselves when the work is done. The 
> next time the timer is activated it first checks the threads are all 
> suspended [i.e. they all finished doing their work last time round]. This is 
> the snag.

When the Execute() function of a TThread object is done, then the thread 
doesn't run anymore and can't run again without making a new instance of 
your thread object. Resume() and Suspend() make no sense on a thread 
which has left the Execute() function. If you don't wan't to make new 
instances of your threads every time, then you should apply a state 
machine in your thread where you can pause, run and exit your thread 
(everything has to be done in a loop in Execute()!). Resume() and 
Suspend() aren't suited for controlling running threads as you don't 
know the state of your thread when it suspends/resumes.

Hope this helps,

Oliver
Technical Details
Message-ID: <429dd4f1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news2.google.com!proxad.net!212.101.4.254.MISMATCH!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <429d7aef$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,a95437282c3feb23
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Wed, 01 Jun 2005 17:31:38 +0200
From: Oliver Rutsch <orutsch@sympatec.com>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8) Gecko/20050511
X-Accept-Language: en-us, en, de-de
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: Converting existing non-threaded app to threaded
References: <429d7aef$1@newsgroups.borland.com>
In-Reply-To: <429d7aef$1@newsgroups.borland.com>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 217.5.250.34
Message-ID: <429dd4f1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1117639921 217.5.250.34 (1 Jun 2005 08:32:01 -0700)
Lines: 38
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news2.google.com!proxad.net!212.101.4.254.MISMATCH!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail