New topic: 

Creating Multiple Instances of A Parse Thread

<http://forums.realsoftware.com/viewtopic.php?t=38704>

         Page 1 of 1
   [ 5 posts ]                 Previous topic | Next topic          Author  
Message        moe          Post subject: Creating Multiple Instances of A 
Parse ThreadPosted: Wed Apr 20, 2011 1:32 pm                         
Joined: Mon Nov 24, 2008 12:25 am
Posts: 103                Hi all,

Please excuse me, if this is a trivial question.

In my project window, I created a subclass of Thread and called it 
MyParseThread for the parsing of XML responses.

When my TCPSocket has received all the data of a particular response, it hands 
it off to MyParseThread and runs.

Now, it is possible that MyParseThread will be running (parsing) while another 
response comes in from the TCPSocket.

So, my question is, is it proper to delay the next MyParseThread run with a 
loop before running MyParseThread again with the new response?
Code:  while MyParseThread.State = Thread.Running
  // Do nothing
  wend
  MyParseThread1.Response = WhatTheTCPSocketReceived
  MyParseThread.Run
  

Or, should I create a new instance of MyParseThread and immediately run it, 
each time the TCPSocket receives a new response?
Code:Dim MyParseThread1 as New MyParseThread
MyParseThread1.Response = WhatTheTCPSocketReceived
MyParseThread1.Run


If it's proper to do the latter, does Realbasic automatically handle the 
destroying of MyParseThread1 when is done running?

Many Thanks!   
                             Top                mjh          Post subject: Re: 
Creating Multiple Instances of A Parse ThreadPosted: Wed Apr 20, 2011 1:51 pm   
                              
Joined: Sun Feb 19, 2006 3:10 pm
Posts: 1245
Location: Hamburg, Germany                Since all threads are running on the 
same CPU, creating additional threads won’t make things go faster. With one 
exception: If a thread may have to wait – for user input or whatever – 
before continuing, then a second thread could run while the first is idle. In 
that case multiple threads would make better use of the available CPU cycles 
than a single thread could. Parsing data doesn’t look like the type of task 
that would ever need to wait – all the data is ready to be parsed once the 
thread starts – so creating additional threads would just increase the 
overhead. In this kind of situation I would create some kind of FIFO buffer 
linking the TCPSocket and the (single) parser thread.      
_________________
Michael J. Hußmann 
http://digicam-experts.de  
                             Top                moe          Post subject: Re: 
Creating Multiple Instances of A Parse ThreadPosted: Wed Apr 20, 2011 3:46 pm   
                      
Joined: Mon Nov 24, 2008 12:25 am
Posts: 103                I'm not looking to make things faster.  I'm only 
trying to deal with parsing all responses from the TCPSocket, successfully.

Sometimes responses can come back over the TCPSocket very fast and 
MyParseThread is still in the middle of parsing the previous response received.

Are you saying my delay loop is sufficient?

Many Thanks!   
                             Top                mjh          Post subject: Re: 
Creating Multiple Instances of A Parse ThreadPosted: Wed Apr 20, 2011 3:54 pm   
                              
Joined: Sun Feb 19, 2006 3:10 pm
Posts: 1245
Location: Hamburg, Germany                No, I would recommend using a FIFO 
buffer – in other words, a queue – for decoupling the TCPSocket and the 
thread. Whenever the TCPSocket receives new data, it puts it into the queue. 
The parse thread takes a chunk of data off the queue, processes it, then, when 
it has finished parsing, takes the next chunk of data off the queue, and so on. 
There’s no need for a delay loop.      
_________________
Michael J. Hußmann 
http://digicam-experts.de  
                             Top                moe          Post subject: Re: 
Creating Multiple Instances of A Parse ThreadPosted: Wed Apr 20, 2011 4:51 pm   
                      
Joined: Mon Nov 24, 2008 12:25 am
Posts: 103                Would you be able to steer me to an example of a 
queue made with Realbasic?

Many Thanks!   
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 5 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to