New topic: 

Threads - Is this allowed /safe?

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

         Page 1 of 1
   [ 1 post ]                 Previous topic | Next topic          Author  
Message        lukus001          Post subject: Threads - Is this allowed 
/safe?Posted: Tue Mar 12, 2013 11:56 am                         
Joined: Sat Jul 16, 2011 2:45 pm
Posts: 54                Hi guys,

I know sharing resources between threads is generally done via a 
CriticalSection but will the following be acceptable?

So example:  I have a TCP stream open, within this stream will be several 
separate messages such as a video, text, audio, broken down into smaller chunks 
and interleaved. A single thread will handle the data available event and split 
each message into it's own memoryblock (the incoming message is of a known 
size, so the memoryblock is fixed / never resized). Another thread (or set of 
threads) will deserialise the message into a more meaningful format which will 
then get passed down the chain to whatever needs to use it.

So, what I would like to do is simply allow one thread to read from the stream 
and write to the memoryblocks progressively and another thread to read from the 
memoryblocks progressively, without there being a critical selection being 
involved.

Thread 1 is therefore simply writing from start to finish on a memoryblock, and 
thread 2 follows behind deserialising. Plus, I'm guessing if I subclass the 
memory block to add a "bytes written" property, so long as thread 2 only ever 
reads from it, there is no need for a critical section on that.

but this entirely assumes that the memoryblock is simply a linear block of 
bytes and is not dynamically altered in anyway? The only reason i can see it 
changing would be to resize the block, at least for an upwards scale but I will 
not be doing this so I should to use the memory block in this fashion?   
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 1 post ]      
-- 
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