PDA

View Full Version : QThread affinity



brcain
29th August 2007, 18:48
I did a search ... couldn't find this particular question answered.

How is thread affinity determined for non-Qt objects? What mechanism?

For example, I have an application that uses legacy code ... leveraging low-level socket library. When I create the non-Qt socket in the run method of the QThread, how does the Qt threading "know" that the socket has affinity with the child thread? Obviously it doesn't block the process on block read ... just wonder how/why?

Also, are QThreads kernel-level or library threads? It depends upon the OS and what Qt is built upon.

Thanks,
Ben

marcel
29th August 2007, 19:30
Also, are QThreads kernel-level or library threads? It depends upon the OS and what Qt is built upon.For example, on Windows, the _beginthreadex CRT function is used to create a QThread.
I am not sure if the underlying implementation is based on kernel threads, but it should be, since all modern operating systems do that.

Anyway, NT and above have a compliance layer for POSIX(therefore pthreads) but it is not documented and I don't think anyone has ever used it.



How is thread affinity determined for non-Qt objects? What mechanism?

For example, I have an application that uses legacy code ... leveraging low-level socket library. When I create the non-Qt socket in the run method of the QThread, how does the Qt threading "know" that the socket has affinity with the child thread? Obviously it doesn't block the process on block read ... just wonder how/why?

It is not determined in any way. The OS kernel takes care of that.
At the lowest level, the kernel gets the entry point of the code segment for the thread.
The socket code is part of that code segment. Therefore it is executed in the thread's context.

Regards