Search code examples
c++qttbb

Comparison of intel tbb and Qt threadpool


I'm developing a Qt application with multithreading. I used divided my task and put them into the Qt thread pool. But later I found intel tbb which is a professional lib for multithreading, too.

I like the concurrent containers provided in intel tbb but I am wondering if Qt native threadpool lib is more compatible with Qt GUI design.

Aso, I tried to implement my task with both Qt threadpool and intel tbb but can not see much different in runtime.

So which one is more recommend when developing a Qt GUI?


Solution

  • If you need Qt event loop to receive events, use QThread, and use it "right" (don't subclass QThread). Otherwise, use what ever fits your need best. Mixing is no problem, any more than threading in general is a problem: you gotta know what you're doing.


    As for Qt, emitting signals and posting events is generally thread safe, unless you do stupid things.

    QObject instance can have thread affinity only to Qt Thread, which means that the thread's Qt event loop delivers events and queued signals to it. Also note that same applies as in GUI thread: if you block the event loop of a thread, events stop in that thread.

    QObject related methods are generally not thread safe, unless explicitly said to be / written to be. If you notice you are calling QObject subclass method from "wrong" thread, it's probably best to not do so. You may for example need to split the class, invoke methods through the event loop, or not use QObject at all for the thing.