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


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

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


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

示例1: tryStartCount

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) {
        int count = 0;
        while (threadPool.tryStart(&task))
            ++count;
        QCOMPARE(count, QThread::idealThreadCount());

        QTest::qWait(100);
    }
}
开发者ID:,项目名称:,代码行数:26,代码来源:

示例2: 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,代码来源:

示例3: PyBool_FromLong

static PyObject *meth_QThreadPool_tryStart(PyObject *sipSelf, PyObject *sipArgs)
{
    PyObject *sipParseErr = NULL;

    {
        QRunnable* a0;
        PyObject *a0Wrapper;
        QThreadPool *sipCpp;

        if (sipParseArgs(&sipParseErr, sipArgs, "[email protected]", &sipSelf, sipType_QThreadPool, &sipCpp, &a0Wrapper, sipType_QRunnable, &a0))
        {
            bool sipRes = 0;

#line 53 "/Users/Kunwiji/Dropbox/Spectroscopy_paper/PyQt-mac-gpl-4.11.2/sip/QtCore/qthreadpool.sip"
            // We have to handle the object ownership manually.
            if (a0->autoDelete())
                sipTransferTo(a0Wrapper, sipSelf);

            Py_BEGIN_ALLOW_THREADS
            sipRes = sipCpp->tryStart(a0);
            Py_END_ALLOW_THREADS
#line 362 "/Users/Kunwiji/Dropbox/Spectroscopy_paper/PyQt-mac-gpl-4.11.2/QtCore/sipQtCoreQThreadPool.cpp"

            return PyBool_FromLong(sipRes);
        }
    }
开发者ID:kunwijik,项目名称:Spectroscopy_paper,代码行数:26,代码来源:sipQtCoreQThreadPool.cpp

示例4: tryStartPeakThreadCount

void tst_QThreadPool::tryStartPeakThreadCount()
{
    class CounterTask : public QRunnable
    {
    public:
        CounterTask() { setAutoDelete(false); }

        void run()
        {
            {
                QMutexLocker lock(&mutex);
                ++activeThreads;
                peakActiveThreads = qMax(peakActiveThreads, activeThreads);
            }

            QTest::qWait(100);
            {
                QMutexLocker lock(&mutex);
                --activeThreads;
            }
        }
    };

    CounterTask task;
    QThreadPool threadPool;

    for (int i = 0; i < 20; ++i) {
        if (threadPool.tryStart(&task) == false)
            QTest::qWait(10);
    }
    QCOMPARE(peakActiveThreads, QThread::idealThreadCount());

    for (int i = 0; i < 20; ++i) {
        if (threadPool.tryStart(&task) == false)
            QTest::qWait(10);
    }
    QCOMPARE(peakActiveThreads, QThread::idealThreadCount());
}
开发者ID:,项目名称:,代码行数:38,代码来源:


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