[Interest] QThreadPool - global instance or custom one

Thiago Macieira thiago.macieira at intel.com
Fri Jan 20 03:29:35 CET 2017


On sexta-feira, 20 de janeiro de 2017 11:59:31 PST Frank Rueter | OHUfx wrote:
> Hi all,
> 
> I have started using QThreadPool for the first time and am wondering if
> it's save/recommended to create my own instance of it or to always use
> the global instance?

The rule I use is that you should use your own pool if you plan on launching 
tasks that may block, but it's ok to use the global one if you need to run 
things that run as fast as they can without blocking.

QHostInfo uses its own thread pool because it calls a blocking function that 
is known to sometimes take 30 seconds to return (getaddrinfo).

> In my case my app will run inside a host application, so my gut feeling
> says to create my own thread pool so I don't accidentally hijack the
> host application's pool, but I may be wrong?!

You're probably right. QHostInfo's example also matches your thinking: Qt's 
behind-the-scenes usage should not affect the main application's ability to 
use the global thread pool.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Interest mailing list