Article View: borland.public.cppbuilder.nativeapi
Article #6205Re: Converting existing non-threaded app to threaded
From: Matt Ross
Date: Thu, 02 Jun 2005 14:53
Date: Thu, 02 Jun 2005 14:53
53 lines
3427 bytes
3427 bytes
"Oliver Rutsch" <orutsch@sympatec.com> wrote in message news:429f0041@newsgroups.borland.com... > Hi Matt, > >>>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. >> >> >> This is a conversion of an existing application which has many instances >> of these two classes. As they have quite a bit of code in each to handle >> behaviour I could not think of any other logical way of threading each so >> they run independently of each other. >> > > I don't know your code, but 500 threads working on their Execute() > functions aren't faster than 500 times running "EstablishBehaviour" on > your objects sequently. The speed of execution is not the main issue here. In order for each agent to be as independent as possible, running each in its own thread means I'm eliminating the sequential nature of running through them in a loop. It currently uses the loop but the PhD supervisors overlooking this project have requested it to be threaded. >> My Execute function is running a loop already that repeats >> EstablishBehaviour followed by Suspend. My main class then uses a timer >> to Resume them so the EstablishBehaviour is run again. The Execute >> function is not ended until the simulation is terminated or the >> application exited. Here is the actual code: >> > > O.K. then you should google for "TThread::Suspended not reliable?", maybe > that's your problem. As mentioned here before I would work with events to > control the thread and I wouldn't use Resume()/Suspend() anymore, with one > exception: I would always create the threads suspended and resume them on > the end of the constructor. Why? If you create a thread non-suspended then > the Execute() function may run before your constructor has run. And then > you're probably working with unitialized member vars in the Execute() > function and you'll get some nice effects ;-) > > Bye, Oliver I already start them suspended. I agree about using events though, and that's what I will be looking at next. Thanks, -- Matt Ross -=I haven't lost my mind; it's backed up on tape.=-
Technical Details
Message-ID:
<429f1d8a@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<429d7aef$1@newsgroups.borland.com> <429dd4f1@newsgroups.borland.com> <429ec62c$1@newsgroups.borland.com> <429f0041@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 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> <429dd4f1@newsgroups.borland.com> <429ec62c$1@newsgroups.borland.com> <429f0041@newsgroups.borland.com> Subject: Re: Converting existing non-threaded app to threaded Date: Thu, 2 Jun 2005 15:53:43 +0100 Lines: 55 Organization: University of Hertfordshire X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2527 X-RFC2646: Format=Flowed; Response X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527 NNTP-Posting-Host: 147.197.236.174 Message-ID: <429f1d8a@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1117724042 147.197.236.174 (2 Jun 2005 07:54:02 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail