本文整理汇总了C++中QThreadPool类的典型用法代码示例。如果您正苦于以下问题:C++ QThreadPool类的具体用法?C++ QThreadPool怎么用?C++ QThreadPool使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QThreadPool类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SleeperTask
void tst_QThreadPool::tryStartCount()
{
class SleeperTask : public QRunnable
{
public:
SleeperTask() { setAutoDelete(false); }
void run()
{
QTest::qWait(50);
}
};
SleeperTask task;
QThreadPool threadPool;
const int runs = 5;
for (int i = 0; i < runs; ++i) {
// qDebug() << "iteration" << i;
int count = 0;
while (threadPool.tryStart(&task))
++count;
QCOMPARE(count, QThread::idealThreadCount());
QTest::qWait(100);
}
}
示例2: BlockedTask
void tst_QThreadPool::waitForDoneTimeout()
{
class BlockedTask : public QRunnable
{
public:
QMutex mutex;
BlockedTask() { setAutoDelete(false); }
void run()
{
mutex.lock();
mutex.unlock();
QTest::qSleep(50);
}
};
QThreadPool threadPool;
BlockedTask *task = new BlockedTask;
task->mutex.lock();
threadPool.start(task);
QVERIFY(!threadPool.waitForDone(100));
task->mutex.unlock();
QVERIFY(threadPool.waitForDone(400));
}
示例3: waitForDone
void tst_QThreadPool::waitForDone()
{
QTime total, pass;
total.start();
QThreadPool threadPool;
while (total.elapsed() < 10000) {
int runs;
runs = count = 0;
pass.restart();
while (pass.elapsed() < 100) {
threadPool.start(new CountingRunnable());
++runs;
}
threadPool.waitForDone();
QCOMPARE(int(count), runs);
runs = count = 0;
pass.restart();
while (pass.elapsed() < 100) {
threadPool.start(new CountingRunnable());
threadPool.start(new CountingRunnable());
runs += 2;
}
threadPool.waitForDone();
QCOMPARE(int(count), runs);
}
}
示例4: manipulator
void QmitkMatchPointRegistrationManipulator::OnStoreBtnPushed()
{
mitk::MAPRegistrationWrapper::Pointer newRegWrapper = mitk::MAPRegistrationWrapper::New();
MAPRegistrationType::Pointer newReg = MAPRegistrationType::New();
newRegWrapper->SetRegistration(newReg);
::map::core::RegistrationManipulator<MAPRegistrationType> manipulator(newReg);
::map::core::PreCachedRegistrationKernel<3, 3>::Pointer kernel = ::map::core::PreCachedRegistrationKernel<3, 3>::New();
kernel->setTransformModel(m_InverseCurrentTransform);
::map::core::PreCachedRegistrationKernel<3, 3>::Pointer kernel2 = ::map::core::PreCachedRegistrationKernel<3, 3>::New();
kernel2->setTransformModel(m_InverseCurrentTransform->GetInverseTransform());
manipulator.setInverseMapping(kernel);
manipulator.setDirectMapping(kernel2);
if (this->m_Controls.radioSelectedReg->isChecked())
{ //compine registration with selected pre registration as baseline
typedef ::map::core::RegistrationCombinator<MAPRegistrationType, MAPRegistrationType> CombinatorType;
CombinatorType::Pointer combinator = CombinatorType::New();
newReg = combinator->process(*m_SelectedPreReg,*newReg);
newRegWrapper->SetRegistration(newReg);
}
mitk::DataNode::Pointer spResultRegistrationNode = mitk::generateRegistrationResultNode(
this->m_Controls.lbNewRegName->text().toStdString(), newRegWrapper, "org.mitk::manual_registration",
mitk::EnsureUID(m_SelectedMovingNode->GetData()), mitk::EnsureUID(m_SelectedTargetNode->GetData()));
this->GetDataStorage()->Add(spResultRegistrationNode);
if (m_Controls.checkMapEntity->checkState() == Qt::Checked)
{
QmitkMappingJob* pMapJob = new QmitkMappingJob();
pMapJob->setAutoDelete(true);
pMapJob->m_spInputData = this->m_SelectedMovingNode->GetData();
pMapJob->m_InputDataUID = mitk::EnsureUID(m_SelectedMovingNode->GetData());
pMapJob->m_spRegNode = spResultRegistrationNode;
pMapJob->m_doGeometryRefinement = false;
pMapJob->m_spRefGeometry = this->m_SelectedTargetNode->GetData()->GetGeometry()->Clone().GetPointer();
pMapJob->m_MappedName = this->m_Controls.lbNewRegName->text().toStdString() + std::string(" mapped moving data");
pMapJob->m_allowUndefPixels = true;
pMapJob->m_paddingValue = 100;
pMapJob->m_allowUnregPixels = true;
pMapJob->m_errorValue = 200;
pMapJob->m_InterpolatorLabel = "Linear Interpolation";
pMapJob->m_InterpolatorType = mitk::ImageMappingInterpolator::Linear;
connect(pMapJob, SIGNAL(Error(QString)), this, SLOT(OnMapJobError(QString)));
connect(pMapJob, SIGNAL(MapResultIsAvailable(mitk::BaseData::Pointer, const QmitkMappingJob*)),
this, SLOT(OnMapResultIsAvailable(mitk::BaseData::Pointer, const QmitkMappingJob*)),
Qt::BlockingQueuedConnection);
QThreadPool* threadPool = QThreadPool::globalInstance();
threadPool->start(pMapJob);
}
示例5: start
void Task::start( Task::action action,function_t function )
{
m_function = function ;
m_action = action ;
QThreadPool * thread = QThreadPool::globalInstance() ;
thread->setMaxThreadCount( 10 ) ;
thread->start( this ) ;
}
示例6: VESPERSRoperQRunnableImageLoader
void VESPERSRoperCCDDetector::loadImageFromFileImplementation(const QString &filename)
{
VESPERSRoperQRunnableImageLoader *runner = new VESPERSRoperQRunnableImageLoader(filename, imageData_.size());
runner->setAutoDelete(true);
QThreadPool *threads = QThreadPool::globalInstance();
connect(runner, SIGNAL(imageData(QVector<int>)), this, SLOT(onImageDataChanged(QVector<int>)));
threads->start(runner);
}
示例7: runFunction
void tst_QThreadPool::runFunction()
{
{
QThreadPool manager;
testFunctionCount = 0;
manager.start(createTask(noSleepTestFunction));
}
QCOMPARE(testFunctionCount, 1);
}
示例8: runTask
void tst_QThreadPool::runTask()
{
QThreadPool manager;
ran = false;
manager.start(new TestTask());
// Hang if task is not runned.
while (ran == false)
QTest::qSleep(100); // no busy loop - this doesn't work with FIFO schedulers
}
示例9: QThreadPool
/*
Test that the ThreadManager destructor waits until
all threads have completed.
*/
void tst_QThreadPool::destruction()
{
value = new int;
QThreadPool *threadManager = new QThreadPool();
threadManager->start(new IntAccessor());
threadManager->start(new IntAccessor());
delete threadManager;
delete value;
value = 0;
}
示例10: waitcomplete
void tst_QThreadPool::waitcomplete()
{
testFunctionCount = 0;
const int runs = 500;
for (int i = 0; i < 500; ++i) {
QThreadPool pool;
pool.start(createTask(noSleepTestFunction));
}
QCOMPARE(testFunctionCount, runs);
}
示例11: expiryTimeout
void tst_QThreadPool::expiryTimeout()
{
ExpiryTimeoutTask task;
QThreadPool threadPool;
threadPool.setMaxThreadCount(1);
int expiryTimeout = threadPool.expiryTimeout();
threadPool.setExpiryTimeout(1000);
QCOMPARE(threadPool.expiryTimeout(), 1000);
// run the task
threadPool.start(&task);
QVERIFY(task.semaphore.tryAcquire(1, 10000));
QCOMPARE(task.runCount, 1);
QVERIFY(!task.thread->wait(100));
// thread should expire
QThread *firstThread = task.thread;
QVERIFY(task.thread->wait(10000));
// run task again, thread should be restarted
threadPool.start(&task);
QVERIFY(task.semaphore.tryAcquire(1, 10000));
QCOMPARE(task.runCount, 2);
QVERIFY(!task.thread->wait(100));
// thread should expire again
QVERIFY(task.thread->wait(10000));
// thread pool should have reused the expired thread (instead of
// starting a new one)
QCOMPARE(firstThread, task.thread);
threadPool.setExpiryTimeout(expiryTimeout);
QCOMPARE(threadPool.expiryTimeout(), expiryTimeout);
}
示例12:
QLandmarkManagerEngineSqlite::~QLandmarkManagerEngineSqlite()
{
QThreadPool *threadPool = QThreadPool::globalInstance();
threadPool->waitForDone();
if (m_dbWatcher !=0)
delete m_dbWatcher;
QSqlDatabase::database(m_dbConnectionName).close();
QSqlDatabase::removeDatabase(m_dbConnectionName);
}
示例13: tr
void MainWindow::openAn2k()
{
QString file = QFileDialog::getOpenFileName(this, tr("qwsqviewer"), QString(), tr("AN2K images (*.an2)"));
if (file.isEmpty())
return;
_loader->setFile(file);
QThreadPool *threadPool = QThreadPool::globalInstance();
threadPool->start(_loader);
}
示例14: start
void tst_QThreadPool::start()
{
const int runs = 1000;
count.store(0);
{
QThreadPool threadPool;
for (int i = 0; i< runs; ++i) {
threadPool.start(new CountingRunnable());
}
}
QCOMPARE(count.load(), runs);
}
示例15: RunProcess
//! Helper function that initiates the image processing algorithms.
void MRIOpenCV::RunProcess()
{
QThreadPool *threadPool = QThreadPool::globalInstance();
for(int i=0; i < this->Processes->size(); i++){
cout << this->Processes->size();
MRIProcess * process= this->Processes->front();
this->Processes->pop();
process->run();
//threadPool->start(process);
}
threadPool->waitForDone();
}