PDA

View Full Version : How set a processor affinity mask for the specified thread?



Ritor
21st August 2009, 13:59
Hi

I need sets a processor affinity mask for the specified thread.
In MS VC I can do this by function SetThreadAffinityMask.
But I can't find same function in QT :(

Somebody can help me?

Thanks!

yogeshgokul
21st August 2009, 14:10
From Qt Docs :


void QObject::moveToThread ( QThread * targetThread )
Changes the thread affinity for this object and its children. The object cannot be moved if it has a parent. Event processing will continue in the targetThread.

burnttoy
21st August 2009, 15:10
Hiya,

I don't think "moveToThread" is what is needed here. That will make the "owner" of that object the thread specified (which changes the way events and signal/object marshalling are handled).

What is required, I think, is the ability to say "this thread runs on this processor". I'm not sure that this is possible in Qt but the QtConcurrent framework should handle some of these problems (it will map an algorithm across multiple CPU's taking care of the threading for you).

I'm afraid I'm not sure there's any way of handling processor inside Qt.

@Ritor. What functionality are you trying to achieve here?

yogeshgokul
21st August 2009, 15:48
Sorry !!
I Overlooked, he need to set Processor affinity not Thread affinity. :crying:
Anyway I don't think so thats possible in Qt in platform independent way.:crying:

Ritor
21st August 2009, 16:00
I have several thread. And I need to one thread execute on one core (processor) and the second thread execute on second core (processor).

I think QtConcurrent perform another function. Or I mistaken?

yogeshgokul
21st August 2009, 16:10
I have several thread. And I need to one thread execute on one core (processor) and the second thread execute on second core (processor).
This is handled by OS not be program. And on most of the OS this is default behavior. Means If we created a threaded app. Then all cores of CPU will be utilized equally.



I think QtConcurrent perform another function. Or I mistaken?
Programs written with QtConcurrent automatically adjust the number of threads used according to the number of processor cores available.