Article View: borland.public.cppbuilder.nativeapi
Article #6201Re: Converting existing non-threaded app to threaded
From: Oliver Rutsch
Date: Thu, 02 Jun 2005 12:48
Date: Thu, 02 Jun 2005 12:48
38 lines
2742 bytes
2742 bytes
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. > > > 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
Technical Details
Message-ID:
<429f0041@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news-out.nntp.be!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<429d7aef$1@newsgroups.borland.com> <429dd4f1@newsgroups.borland.com> <429ec62c$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: Thu, 02 Jun 2005 14:48:41 +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> <429dd4f1@newsgroups.borland.com> <429ec62c$1@newsgroups.borland.com> In-Reply-To: <429ec62c$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: <429f0041@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1117716545 217.5.250.34 (2 Jun 2005 05:49:05 -0700) Lines: 38 Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news-out.nntp.be!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail