[Qt-interest] High performance pipeline (QThread)

Arnold Krille arnold at arnoldarts.de
Fri Oct 1 00:37:06 CEST 2010


On Thursday 30 September 2010 21:19:33 Thomas Richard wrote:
> Hey all,
> 
> My objective is to build a library that is able to grab some data from
> somewhere and then do some heavy calculations on this data. These
> calculations happen in steps, and it'd like to take advantage of
> multithreading here. Basically what i need is a pipeline that passes
> results from one thread to another. A catch is that more threads can
> be subscribed on the results of a previous thread. So the pipeline can
> split up.
> 
> I first thought about implementing this using QWaitCondition, which
> will probably be the most performant way to do it. I'm afraid it will
> get very complex pretty soon though and deadlocks are easy to create.
> My second thought was to give each thread it's own eventloop and
> communicate using queued signal/slot connections. This would be way
> more easy to maintain but.. here (finally) comes my question:
> What's the cost of doing this. Will i lose alot of speed using
> signal/slot connections or is this loss unsignificant? What are the
> downsides of running an eventloop in each thread?

There is a small overhead coming from eventloop and signals/slots.

But: If its only one data-type that gets pushed around, its easier to derive 
all workers from the same base-class. And that base-class has an incoming 
queue for your data-type. That queue has to have locks on the receiving side. 
And when its always only one queue per receiving worker, you can drop that. 
And it needs a lock when one worker can receive data from multiple other 
workers.
You can then either push around pointers to your data. But then you have to 
deal with deletion or reference-counting yourself.
You can also encapsulate the (probably already defined) data-structure in a 
master-type that uses QShared* to do the ref-counting for you and delete the 
data once it isn't used anymore.

Maybe that helps you...

Arnold
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20101001/6f9c4cf9/attachment.bin 


More information about the Qt-interest-old mailing list