[Qt-interest] Using QThreads for parallel diffusion

Andrew Hodgkinson ahodgkinson at endurancetech.co.uk
Fri Oct 23 12:57:49 CEST 2009


On 23/10/2009 10:48, Samuel Rødal wrote:

>> I am trying use QThreads for a numerical calculations [...]
>> (I am running on a mac pro with dual quad core
>> processors 6GB RAM).
>
> I would suggest that you use QtConcurrent instead of manually spawning
> threads.

That's reminiscent of a simple form of OS X 10.6's Grand Central. You 
could consider using this directly if building for a platform which 
includes appropriate support. It's becoming available on FreeBSD now and 
will probably appear on other Unix-like operating systems in due course.

The whole point of the Grand Central architecture is not just to use more 
threads when there are more cores. It's designed to allow the kernel to 
make the best decisions on when to create threads or queue jobs on 
existing worker threads, because of the kind of problems you describe; 
threads may be expensive to create and other cores may already be fully 
committed at any particular instant. For an overview see:

   http://arstechnica.com/apple/reviews/2009/08/mac-os-x-10-6.ars/12
   http://arstechnica.com/apple/reviews/2009/08/mac-os-x-10-6.ars/13

The kernel is involved in the decision making process because it's the 
only place where all the relevant information about all running processes 
and threads is kept at all times. It's not something which can be written 
into a pure userland library alone, but a future Qt API revision might 
expose similar facilities if the underlying OS provided support else 
transparently fall back to a simpler QtConcurrent-like model. Your 
application could adopt a similar approach if you need it to run on any 
Qt-supported platform.

-- 
TTFN, Andrew Hodgkinson
Find some electronic music at:     Photos, wallpaper, software and more:
http://pond.org.uk/music.html                        http://pond.org.uk/



More information about the Qt-interest-old mailing list