🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Converting existing non-threaded app to threaded

#6181
From: Matt Ross
Date: Wed, 01 Jun 2005 09:07
40 lines
3042 bytes
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?

I modified my class TBaseObject to class TThread on both these classes, and 
added all the requisite functions. I also modified the debug output function 
which references back to the main class and the VCL to cope with shared 
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.

The problem I'm having is that most of the time some of these threads never 
make it back to the suspended state. Each time I run the application it 
varies. What's most confusing is that even if I comment everything out in 
the Execute function except the call to Suspend() the threads behave the 
same. On the odd occasion none of the threads get stuck and it works. I have 
been using a loop to read the Suspended attribute and do a Sleep(0) if any 
threads have not finished.

Am I approaching this the right way? I want the timer on the main form to 
control the timing of the threads and this is the way I thought best. 
Unfortunately C++ Builder does not seem to let me step debug into a thread. 
When I set breakpoints in a thread class it ignores them.

Any assistance would be great.

Thanks,

-- 
Matt Ross

-=I haven't lost my mind; it's backed up on tape.=- 
Technical Details
Message-ID: <429d7aef$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,a95437282c3feb23,start
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
Reply-To: "Matt Ross" <m.dot.g.dot.ross@herts.dot.ac.dot.uk>
From: "Matt Ross" <m.dot.g.dot.ross@herts.dot.ac.dot.uk>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Converting existing non-threaded app to threaded
Date: Wed, 1 Jun 2005 10:07:43 +0100
Lines: 42
Organization: University of Hertfordshire
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 147.197.236.174
Message-ID: <429d7aef$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1117616879 147.197.236.174 (1 Jun 2005 02:07:59 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail