本文整理汇总了C++中QThreadPool::start方法的典型用法代码示例。如果您正苦于以下问题:C++ QThreadPool::start方法的具体用法?C++ QThreadPool::start怎么用?C++ QThreadPool::start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QThreadPool
的用法示例。
在下文中一共展示了QThreadPool::start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: destroyingWaitsForTasksToFinish
void tst_QThreadPool::destroyingWaitsForTasksToFinish()
{
QTime total, pass;
total.start();
while (total.elapsed() < 10000) {
int runs;
count.store(runs = 0);
{
QThreadPool threadPool;
pass.restart();
while (pass.elapsed() < 100) {
threadPool.start(new CountingRunnable());
++runs;
}
}
QCOMPARE(count.load(), runs);
count.store(runs = 0);
{
QThreadPool threadPool;
pass.restart();
while (pass.elapsed() < 100) {
threadPool.start(new CountingRunnable());
threadPool.start(new CountingRunnable());
runs += 2;
}
}
QCOMPARE(count.load(), runs);
}
}
示例2: 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);
}
示例3: 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);
}
}
示例4: runMultiple
void tst_QThreadPool::runMultiple()
{
const int runs = 10;
{
QThreadPool manager;
testFunctionCount = 0;
for (int i = 0; i < runs; ++i) {
manager.start(createTask(sleepTestFunctionMutex));
}
}
QCOMPARE(testFunctionCount, runs);
{
QThreadPool manager;
testFunctionCount = 0;
for (int i = 0; i < runs; ++i) {
manager.start(createTask(noSleepTestFunctionMutex));
}
}
QCOMPARE(testFunctionCount, runs);
{
QThreadPool manager;
for (int i = 0; i < 500; ++i)
manager.start(createTask(emptyFunct));
}
}
示例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();
}
示例6: runTask
void tst_QThreadPool::runTask()
{
QThreadPool manager;
ran = false;
manager.start(new TestTask());
QTRY_VERIFY(ran);
}
示例7: 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());
}
示例8: 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();
}
示例9: 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));
}
示例10: detectMinutiae
void MainWindow::detectMinutiae()
{
MinutiaeDetect* md = new MinutiaeDetect(_canvas);
QThreadPool *threadPool = QThreadPool::globalInstance();
threadPool->start(md);
}
示例11: OnStoreBtnPushed
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);
}
示例12: 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 ) ;
}
示例13: loadImageFromFileImplementation
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);
}
示例14: runFunction
void tst_QThreadPool::runFunction()
{
{
QThreadPool manager;
testFunctionCount = 0;
manager.start(createTask(noSleepTestFunction));
}
QCOMPARE(testFunctionCount, 1);
}
示例15: 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
}