[Qt-interest] QThread and multi-core

Arnold Krille arnold at arnoldarts.de
Fri Apr 3 14:57:58 CEST 2009


Hi,

On Friday 03 April 2009 14:19:38 NARCISO, Rui wrote:
> 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 ?

For true parallel execution you have to implement your stuff in C++ and should 
subclass from QThread (unless you want to deal with threads in the native way 
of each platform).
If you just exchange the data via signals/slots, you don't need locks. But be 
aware that this only holds for real signal-slot-connections, as soon as you 
call a slot "by hand" the execution of the slot (which is really just like any 
other function) is the calling thread, not the thread the slots object belongs 
to. You can also use events for your communication, in fact the signal-slot 
connections becomes an event when it crosses thread-boundaries.
And don't worry about speed, I am sending around 10000 events per second for 
usually ten to twelve hours between the threads of my applications without any 
problems.

> Or is the number of QThreads limited somehow?

The number of threads is only limited by the system resources (and maybe by a 
system-dependent overflow of the thread identifier). Note that multiple threads 
only increase the performance up to a certain point, when you create much more 
threads then the number of available cores, the OS will have to switch between 
the processes/threads and the number of context switches reduces the 
performance gain.

Have fun,

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


More information about the Qt-interest-old mailing list