当前位置: 首页>>代码示例>>C++>>正文


C++ QThreadPool::waitForDone方法代码示例

本文整理汇总了C++中QThreadPool::waitForDone方法的典型用法代码示例。如果您正苦于以下问题:C++ QThreadPool::waitForDone方法的具体用法?C++ QThreadPool::waitForDone怎么用?C++ QThreadPool::waitForDone使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QThreadPool的用法示例。


在下文中一共展示了QThreadPool::waitForDone方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: waitForDone

void tst_QThreadPool::waitForDone()
{
    QTime total, pass;
    total.start();

    QThreadPool threadPool;
    while (total.elapsed() < 10000) {
        int runs;
        count.store(runs = 0);
        pass.restart();
        while (pass.elapsed() < 100) {
            threadPool.start(new CountingRunnable());
            ++runs;
        }
        threadPool.waitForDone();
        QCOMPARE(count.load(), runs);

        count.store(runs = 0);
        pass.restart();
        while (pass.elapsed() < 100) {
            threadPool.start(new CountingRunnable());
            threadPool.start(new CountingRunnable());
            runs += 2;
        }
        threadPool.waitForDone();
        QCOMPARE(count.load(), runs);
    }
}
开发者ID:,项目名称:,代码行数:28,代码来源:

示例2: waitForDoneTimeout

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));
}
开发者ID:,项目名称:,代码行数:25,代码来源:

示例3: Compute

float ClusteringCoefficient::Compute() {
    QList<FeaturesComplexNetwork::Node> ids;
    ids.reserve(cn.getNumNodes());
    for(FeaturesComplexNetwork::NodeIt it(cn); it != INVALID; ++it){
        ids.append( it );
    }
    std::random_shuffle(ids.begin(), ids.end());

    QList<QList<FeaturesComplexNetwork::Node>> lists;
    lists.append(QList<FeaturesComplexNetwork::Node>());

    int j=0;
    for(int i=0;i< ids.size()*ratio; i++){
        lists.last().append(ids[i]);
        j++;
        if( j > 50 ){
            j=0;
            lists.append(QList<FeaturesComplexNetwork::Node>());
        }
    }


    FeaturesComplexNetwork::ArcMap<double> weights(cn);
    GraphUtilities::getWeights(cn, weights);
    GraphUtilities::normalizeWeights(cn,weights,weights);

    QThreadPool pool;
    pool.setMaxThreadCount(this->threads);
    for(auto &list : lists) {
        pool.start(new ClusteringCoefficientTask(this, cn, weights, list));
    }
    pool.waitForDone();

    return std::accumulate(ccs.begin(),ccs.end(),0.f, [](const float &a, const ClusteringCoefficient::NodeCC &b){return a+b.cc;})/ccs.size();
}
开发者ID:lopespt,项目名称:PhD-Thesis,代码行数:35,代码来源:ClusteringCoefficient.cpp

示例4: tryStart

void tst_QThreadPool::tryStart()
{
    class WaitingTask : public QRunnable
    {
    public:
        QSemaphore semaphore;

        WaitingTask() { setAutoDelete(false); }

        void run()
        {
            semaphore.acquire();
            count.ref();
        }
    };

    count.store(0);

    WaitingTask task;
    QThreadPool threadPool;
    for (int i = 0; i < threadPool.maxThreadCount(); ++i) {
        threadPool.start(&task);
    }
    QVERIFY(!threadPool.tryStart(&task));
    task.semaphore.release(threadPool.maxThreadCount());
    threadPool.waitForDone();
    QCOMPARE(count.load(), threadPool.maxThreadCount());
}
开发者ID:,项目名称:,代码行数:28,代码来源:

示例5: run

void GDALGeometricAttributes::run()
{

	//return;
	if (useSQL) {
		//run_sql();
		run_sql_threaded();
		return;
	}

	OGRFeature * f;

	vc.resetReading();
	QThreadPool pool;
	std::vector<OGRFeature*> container;
	int counter = 0;
	while( f = vc.getNextFeature() ) {
		container.push_back(f);
		if (counter%10000 == 0){
			GeometricAttributeWorker * gw = new GeometricAttributeWorker(this, container, isCalculateArea, isAspectRationBB , isPercentageFilled);
			pool.start(gw);
			container = std::vector<OGRFeature*>();
		}
	}
	pool.waitForDone();
}
开发者ID:iut-ibk,项目名称:DynaMind-ToolBox,代码行数:26,代码来源:gdalgeometricattributes.cpp

示例6:

QLandmarkManagerEngineSqlite::~QLandmarkManagerEngineSqlite()
{
    QThreadPool *threadPool = QThreadPool::globalInstance();
    threadPool->waitForDone();

    if (m_dbWatcher !=0)
        delete m_dbWatcher;

    QSqlDatabase::database(m_dbConnectionName).close();
    QSqlDatabase::removeDatabase(m_dbConnectionName);
}
开发者ID:,项目名称:,代码行数:11,代码来源:

示例7: 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();
}
开发者ID:CalPolyMABS,项目名称:MRISegmentationProject,代码行数:14,代码来源:MRIOpenCV.cpp

示例8: QMainWindow

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    Work work;
    work.setAutoDelete(false);
    QThreadPool *threadPool = QThreadPool::globalInstance();
    threadPool->start(&work);
    qDebug() << "hello from GUI thread " << QThread::currentThread();
    threadPool->waitForDone();
}
开发者ID:martinedelmann,项目名称:personal,代码行数:13,代码来源:mainwindow.cpp

示例9: benchmarkAlloc

void KisMemoryPoolTest::benchmarkAlloc()
{
    QThreadPool pool;
    pool.setMaxThreadCount(NUM_THREADS);

    QBENCHMARK {
        for(qint32 i = 0; i < NUM_THREADS; i++) {
            KisAllocStressJob *job = new KisAllocStressJob();
            pool.start(job);
        }

        pool.waitForDone();
    }
}
开发者ID:IGLOU-EU,项目名称:krita,代码行数:14,代码来源:kis_memory_pool_test.cpp

示例10: main

int main(int argc, char *argv[])
{
	QCoreApplication app(argc, argv);

	Worker worker;
	worker.setAutoDelete(false);

	QThreadPool *threadPool = QThreadPool::globalInstance();
	threadPool->start(&worker);

	qDebug() << "Hello from GUI thread. ID is " << (int)QThread::currentThreadId();

	threadPool->waitForDone();

	return 0;
}
开发者ID:AlexanderNF,项目名称:thread.pool,代码行数:16,代码来源:main.cpp

示例11: concurrentRequestsShouldWork

void FavIconTest::concurrentRequestsShouldWork()
{
    const int numThreads = 3;
    QThreadPool tp;
    tp.setMaxThreadCount(numThreads);
    QVector<QFuture<QString>> futures(numThreads);
    for (int i = 0; i < numThreads; ++i) {
        futures[i] = QtConcurrent::run(&tp, getAltIconUrl);
    }
    QVERIFY(tp.waitForDone(60000));

    const QString firstResult = futures.at(0).result();
    for (int i = 1; i < numThreads; ++i) {
        QCOMPARE(futures.at(i).result(), firstResult);
    }
    QVERIFY(!QPixmap(firstResult).isNull());
}
开发者ID:KDE,项目名称:kio,代码行数:17,代码来源:favicontest.cpp

示例12: run

void GDALParcelSplit::run()
{
	cityblocks.resetReading();
	OGRFeature *poFeature;
	this->counter_added = 0;

	QThreadPool pool;
	while( (poFeature = cityblocks.getNextFeature()) != NULL ) {
		char* geo;

		poFeature->GetGeometryRef()->exportToWkt(&geo); //Geo destroyed by worker
		ParcelSplitWorker * ps = new ParcelSplitWorker(poFeature->GetFID(), this, this->width, this->target_length, this->splitFirst, geo);
		pool.start(ps);
	}
	pool.waitForDone();
	this->generated = counter_added;
}
开发者ID:iut-ibk,项目名称:DynaMind-ToolBox,代码行数:17,代码来源:gdalparcelsplit.cpp

示例13: process

void ConvolutionFilter::process(const QList<float> &matrix, int radius) {

	QThreadPool threadPool;
	threadPool.setMaxThreadCount(16);
	int height = image.height();

	for (int y = 0; y < height; y++) {
		ConvolutionFilterRunner *runner = new ConvolutionFilterRunner(&image);
		runner->setMatrix(matrix, radius);
		runner->setScanLine((QRgb *) processed.scanLine(y), y);
		runner->setAutoDelete(true);

		threadPool.start(runner);
	}

	printf("waiting for convolution filter...");
	threadPool.waitForDone();
}
开发者ID:anozaki,项目名称:LaserBookDewarp,代码行数:18,代码来源:ConvolutionFilter.cpp

示例14: threadSafety

void tst_QPointer::threadSafety()
{

    QThread owner;
    owner.start();

    QThreadPool pool;
    for (int i = 0; i < 300; i++) {
        QPointer<TestRunnable> task = new TestRunnable;
        task->setAutoDelete(true);
        task->moveToThread(&owner);
        pool.start(task);
    }
    pool.waitForDone();

    owner.quit();
    owner.wait();
}
开发者ID:,项目名称:,代码行数:18,代码来源:

示例15: main

int main(int argc, char *argv[]) {
    QCoreApplication a(argc, argv);

    PayLoad *payLoad = new PayLoad(QCoreApplication::arguments());

    QThreadPool *qThreadPool = QThreadPool::globalInstance();
    qThreadPool->setMaxThreadCount(payLoad->getThreads());

    if(payLoad->verify()) {
        for(int i = 0; i < payLoad->getThreads(); i++){
            qThreadPool->start(new RequestThread(i, payLoad));
        }
        qDebug() << "All threads started ..";
    } else {
        qDebug() <<"Parameters missing";
    }

    qThreadPool->waitForDone();

    qDebug() << "Done";

    return a.exec();
}
开发者ID:matoom,项目名称:stress,代码行数:23,代码来源:main.cpp


注:本文中的QThreadPool::waitForDone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。