Search code examples
c++multithreadingqtcross-platformmulticore

Is QThread on user level, kernel level or both?


I'm writing portable code for multicore machines and I want kernel level threads so the threads can use more than one cpu. After reading QThread documentation on Qt Assistant I still haven't found any hints.

On Windows XP the multithreading example (mandelbrot) from the QtSDK used only one core. So I guess on XP only user level threads are possible. I haven't tested that on Linux or OSX so far since there isn't the full SDK installed. EDIT: The example given in the SDK is stupid - it only uses one thread for those calculation so the binding to only one core was misleading. Buildig a sample myself I could use all cores, so on XP with mingw/GCC Qt uses kernel level threads.

So, what kind of threads are used by QThread? Is it possible to specify what kind of thread to use?

Multiple processes are also an option in combination with shared memory.

Edit

http://doc.qt.io/qt-4.8/thread-basics.html gives a nice introduction.


Solution

  • I don't know about Windows, but on Unix it is using pthreads. QT isn't exposing API for CPU affinity because it needs to be platform- and hardware-independent. The QThread distribution across CPUs is left to the OS scheduler, you can't hint it via some QT API.