[Qt-interest] What exactly is thread affinity, and what is it for?
K. Frank
kfrank29.c at gmail.com
Thu May 20 18:46:34 CEST 2010
Thiago -
Thank you. I have some follow-up questions, please see below.
(I have other questions, as well, but I will ask them in separate replies.)
On Thu, May 20, 2010 at 11:05 AM, Thiago Macieira <thiago at kde.org> wrote:
> Em Quinta-feira 20 Maio 2010, às 16:27:39, K. Frank escreveu:
>> Hello List -
>>
>> My assumption...
>> ...
>> What is thread affinity for?
>> ...
>
> The thread affinity is there to tell which thread's event dispatcher shall be
> used for event-dispatcher activities.
Is the following correct?
A thread has an event dispatcher (or has an event dispatcher that is
properly running) if, and only if the QThread's exec() member function
has been called (and hasn't blocked or been killed).
That is, are "event dispatcher," "event loop," and "exec()" basically all
synonymous?
> The event dispatcher does basically three things:
> 1) it has an event queue
> 2) it has a list of timers
> 3) it has a list of socket notifiers
>
> So when a QObject needs to handle any of those three things, it needs to know
> which thread's event dispatcher it should talk to. The interface to the event
> queue is QCoreApplication::postEvent; the interface to the timers is
> QObject::startTimer (and the convenience classes QBasicTimer and QTimer); the
> interface to socket notifiers is the QSocketNotifier class.
Let me pose a question about the event queue: Let's say I have
QThread *t1 = new QThread...
and an object, o1, that was created by t1's thread of execution.
Any old thread can call QCoreApplication::postEvent (o1, someEvent);. True?
Is it the case that if t1's exec() loop is running, then t1's thread
of execution will call
o1->event (someEvent);
and if t1's exec() loop is not running (wasn't started, or was
blocked, or killed),
o1-event() won't be called?
Is the way postEvent() / event() is handled independent of whether the thread of
execution that calls postEvent is t1's, itself?
Thanks. (And I'll be back...)
K. Frank
> ...
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
> Senior Product Manager - Nokia, Qt Development Frameworks
> ...
More information about the Qt-interest-old
mailing list