Set Thread Priority In QtConcurrent

From Qt Wiki
Revision as of 17:42, 14 January 2015 by Maintenance script (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

How to set thread priority for concurrent threads (QtConcurrent)

QThread class have method setPriority(), but QtConcurrent doesn’t. So i write own implementation with using call_once function. But current C++ standard does not have this function, it’s only in C++0x and BOOST. After some googling i found few implementations and select one. QAtomicInt not ideal class for create thread-safe code and i had to use few undocumented features like QBasicAtomicInt, because it POD type and can be initialized statically inside executable file before all potential parallel initializations inside concurrent threads.

This is example how to use this functions for set thread priority once per thread at run:

Source [forum.crossplatform.ru]

P.S.: this implementation faster than boost::call_once, but slower than std::call_once

Categories: