🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Converting existing non-threaded app to threaded

#6199
From: Matt Ross
Date: Thu, 02 Jun 2005 09:58
56 lines
3267 bytes
"Bob Gonder" <notbg@notmindspring.invalid> wrote in message 
news:r5pr915usa5ffe44er8fif4un793sol0gc@4ax.com...
> Matt Ross wrote:
>
>>
>>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.
>
> How about this.
> Instead of using Resume, have the main thread set up 4 manual-reset
> event 2 for animals, 2 for flood.
> Each thread enters an outter loop the locks and incriments a static
> counter...psudo code might be faster to explain....
[snipped]

Yes it looks like I should be using events to determine when each thread has 
finished its current iteration.

> When main receives MSG_BarnFull, then it could either enable the
> timer, or just go ahead with the next round.
>
>>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
>
> If this is like the game of life, where each node is dependant upon
> the state of it's neighbors, and you are locking access to neighbors
> who are locking access to you...could be a deadlock.

The agents do not interact with each other directly in this way. I have 
another class called Grid that handles where everyone/everything is located 
and each agent adds to a queue of things to add/move/delete for the current 
iteration. Once all the threads are suspended the Grid updates itself ready 
for the next iteration.

I will look at using Events to signal when the threads are ready and see how 
it goes.

Thanks,

-- 
Matt Ross

-=I haven't lost my mind; it's backed up on tape.=- 
Technical Details
Message-ID: <429ed852@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news2.google.com!proxad.net!fr.ip.ndsoftware.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <429d7aef$1@newsgroups.borland.com> <r5pr915usa5ffe44er8fif4un793sol0gc@4ax.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,a95437282c3feb23
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
References: <429d7aef$1@newsgroups.borland.com> <r5pr915usa5ffe44er8fif4un793sol0gc@4ax.com>
Subject: Re: Converting existing non-threaded app to threaded
Date: Thu, 2 Jun 2005 10:58:23 +0100
Lines: 58
Organization: University of Hertfordshire
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
NNTP-Posting-Host: 147.197.236.174
Message-ID: <429ed852@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1117706322 147.197.236.174 (2 Jun 2005 02:58:42 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news2.google.com!proxad.net!fr.ip.ndsoftware.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail