These methods are used to interact with a thread pool with threads that you manually manage.
, , . reserveThread releaseThread , . . , QThread.
reserveThread : " , , , , , , ( ).
releaseThread : " , ".
: . - ++.
:
QThreadPool pool;
assert(pool.maxThreadCount() == 4);
assert(pool.activeThreadCount() == 0);
: . , reserveThread:
MyWorker worker;
QThread thread;
worker.moveToThread(&thread);
thread.start();
pool.reserveThread();
assert(pool.activeThreadCount() == 1);
!
runnables, . :
QAtomicInt act = 0;
QtConcurrent.run(&pool, [&]{ act.ref(); QThread::sleep(60); act.deref(); });
QtConcurrent.run(&pool, [&]{ act.ref(); QThread::sleep(60); act.deref(); });
QtConcurrent.run(&pool, [&]{ act.ref(); QThread::sleep(60); act.deref(); });
QtConcurrent.run(&pool, [&]{ act.ref(); QThread::sleep(60); act.deref(); });
QThread::sleep(1);
assert(pool.activeThreadCount() == 4);
assert(act.load() == 3);
runnables, : , .
, . , releaseThread:
thread.quit();
thread.wait();
pool.releaseThread();
QThread::sleep(1);
assert(pool.activeThreadCount() == 4);
assert(act.load() == 4);
runnable, , runnable.
, :
QThread::sleep(60);
assert(pool.activeThreadCount() == 0);
assert(act.load() == 0);