[Qt-interest] QThread and multi-core

Paul Floyd paulf at free.fr
Fri Apr 3 17:21:21 CEST 2009


Quoting "NARCISO, Rui" <RUI.NARCISO at airbus.com>:

>
> So if I understand correctly, I should use QThreads instead of python threads
> and since I use no locking, only signals/slots to communicate with my Gui, I
> could have as many parallel QThreads as the ones I launch ? Or is the number
> of QThreads limited somehow?

Hi

You need to dimension the number of threads that you create depending on the
workload, throughput and the number of CPUs available. On UNIX, for each pthread
that you create (and QThread uses pthreads for the underlying implementation)
then, from the manpage

     attribute.  By default, the stack size is 1 megabyte for 32-
     bit processes and  2  megabyte  for  64-bit  processes  (see
     pthread_attr_setstacksize(3C)).  If  the default is used for

This means that on a 32bit system, you'll have a hard limit of a few thousand
threads (unless you reduce the default stacksize). However, creating thousands
of threads would be a very bad idea.

Your aim should be to keep your CPU utilization as high as possible without
having threads waiting for the CPU. A simple rule of thumb is one thread per
core (perhaps less one for the GUI, perhaps more if the threads spend a lot of
time waiting for IO).

A+
Paul



More information about the Qt-interest-old mailing list