Qt doesn't provide any public APIs for setting processor affinity. There's definitely no way to do this for a QThreadPool
, which doesn't even provide an API for accessing the QThread
s within the pool.
For explicitly-created QThread
objects, you could try using the QThread::getCurrentThreadId()
function to return a native "handle" to the thread, and then pass that to your system's thread-management library calls. But I would strongly recommend against this. The docs explicitly state:
Warning: The handle returned by this function is used for internal purposes and should not be used in any application code.
If you're building for a specific platform, you might be able to mix calls to your OS's library (e.g., pthreads
), but that will not be portable and I have no idea if it will work.
Your best bet is probably to manage the CPU affinity of the whole application from the command-line. If you're on Linux, taskset
is the way to go. For Windows, take a look at this SO answer. Unfortunately, Apple seems pretty determined to prevent users from setting thread affinity, at least from the command line.