C++ (Qt)Worker* worker = new Worker; // Inherit QRunnable QThreadPool *threadPool = new QThreadPool; for(int i=0; i < 20; i++) { if(!threadPool->globalInstance()->tryStart(worker)) qDebug() << i << " tryStart = false"; else qDebug() << i << " tryStart = true"; };
C++ (Qt)Worker* worker = new Worker; // Inherit QRunnableQThreadPool *threadPool = new QThreadPool; qDebug() << "activeThreadCount: " << threadPool->activeThreadCount(); for(int i=0; i < 20; i++) threadPool->globalInstance()->tryStart(worker); qDebug() << "activeThreadCount: " << threadPool->activeThreadCount();
C++ (Qt)void Worker::run(){ QThread::sleep(10); // Pause 10 sec}
C++ (Qt)QThreadPool* threadPool = new QThreadPool; threadPool->reserveThread();threadPool->reserveThread();threadPool->reserveThread(); qDebug() << "Active Threads: " << threadPool->activeThreadCount(); //Will show active Threads