Search code examples
c++qtloggingconcurrencyqthread

Does a frequent calls to `QThread::currentThread()` during logging affect the performance significantly?


In my multi-threaded application, with every log I intend to print the thread information. For that, I have to invoke QThread::currentThread()->objectName() every time.

Here is its source code:

QThread* QThread::currentThread() { return QThreadData::current()->thread.loadAcquire(); }

Was wondering if it will affect the overall performance significantly when the logging increases. I don't have a deterministic way to quantify this information myself.


Solution

  • In latest Qt, it is implemented with std::memory_order_acquire. According to the document, "No additional CPU instructions are issued for this synchronization mode" in x86.

    Assume you are using this on intel machines, this would be good.