[Qt-interest] What exactly is thread affinity, and what is it for?

K. Frank kfrank29.c at gmail.com
Thu May 20 16:27:39 CEST 2010


Hello List -

My assumption is that Qt's thread affinity is an association between
a QObject (or derived class) and a specific instance of a QThread (or
derived classes).  (Hypothetically, QObject could contain a QThread*
data member that points to the QThread for which it has affinity,
although I don't claim that it is necessarily implemented this way.)

Is this an accurate description of thread affinity?

What is thread affinity for?  My understanding is that the main purpose
(sole purpose?) of thread affinity is to determine whether a signal/slot
connection is made through a Direct Connection or a Queued Connection:
if the emitter (the instance of the class with the signal) and the receiver
(the instance of the class with the slot) have the same thread affinity,
the connection is direct, and if they have different thread affinities, the
connection is queued.

Is this right?  Is this the main use of thread affinity?  Is thread affinity
used for other things as well?

(These questions are motivated by an earlier post that tried to probe
the behavior of some QThread and signal/slot example code.)

Thanks for any insight.


K. Frank



More information about the Qt-interest-old mailing list