本文整理汇总了C++中QThreadPool::releaseThread方法的典型用法代码示例。如果您正苦于以下问题:C++ QThreadPool::releaseThread方法的具体用法?C++ QThreadPool::releaseThread怎么用?C++ QThreadPool::releaseThread使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QThreadPool
的用法示例。
在下文中一共展示了QThreadPool::releaseThread方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: reserveThread
void tst_QThreadPool::reserveThread()
{
QFETCH(int, limit);
QThreadPool *threadpool = QThreadPool::globalInstance();
int savedLimit = threadpool->maxThreadCount();
threadpool->setMaxThreadCount(limit);
// reserve up to the limit
for (int i = 0; i < limit; ++i)
threadpool->reserveThread();
// reserveThread() should always reserve a thread, regardless of
// how many have been previously reserved
threadpool->reserveThread();
QCOMPARE(threadpool->activeThreadCount(), (limit > 0 ? limit : 0) + 1);
threadpool->reserveThread();
QCOMPARE(threadpool->activeThreadCount(), (limit > 0 ? limit : 0) + 2);
// cleanup
threadpool->releaseThread();
threadpool->releaseThread();
for (int i = 0; i < limit; ++i)
threadpool->releaseThread();
// reserving threads in children should not effect the parent
{
QThreadPool threadpool2(threadpool);
threadpool2.setMaxThreadCount(limit);
// reserve up to the limit
for (int i = 0; i < limit; ++i)
threadpool2.reserveThread();
// reserveThread() should always reserve a thread, regardless
// of how many have been previously reserved
threadpool2.reserveThread();
QCOMPARE(threadpool2.activeThreadCount(), (limit > 0 ? limit : 0) + 1);
threadpool2.reserveThread();
QCOMPARE(threadpool2.activeThreadCount(), (limit > 0 ? limit : 0) + 2);
threadpool->reserveThread();
QCOMPARE(threadpool->activeThreadCount(), 1);
threadpool->reserveThread();
QCOMPARE(threadpool->activeThreadCount(), 2);
// cleanup
threadpool2.releaseThread();
threadpool2.releaseThread();
threadpool->releaseThread();
threadpool->releaseThread();
while (threadpool2.activeThreadCount() > 0)
threadpool2.releaseThread();
}
// reset limit on global QThreadPool
threadpool->setMaxThreadCount(savedLimit);
}
示例2: releaseThread
void tst_QThreadPool::releaseThread()
{
QFETCH(int, limit);
QThreadPool *threadpool = QThreadPool::globalInstance();
int savedLimit = threadpool->maxThreadCount();
threadpool->setMaxThreadCount(limit);
// reserve up to the limit
for (int i = 0; i < limit; ++i)
threadpool->reserveThread();
// release should decrease the number of reserved threads
int reserved = threadpool->activeThreadCount();
while (reserved-- > 0) {
threadpool->releaseThread();
QCOMPARE(threadpool->activeThreadCount(), reserved);
}
QCOMPARE(threadpool->activeThreadCount(), 0);
// releaseThread() can release more than have been reserved
threadpool->releaseThread();
QCOMPARE(threadpool->activeThreadCount(), -1);
threadpool->reserveThread();
QCOMPARE(threadpool->activeThreadCount(), 0);
// releasing threads in children should not effect the parent
{
QThreadPool threadpool2(threadpool);
threadpool2.setMaxThreadCount(limit);
// reserve up to the limit
for (int i = 0; i < limit; ++i)
threadpool2.reserveThread();
// release should decrease the number of reserved threads
int reserved = threadpool2.activeThreadCount();
while (reserved-- > 0) {
threadpool2.releaseThread();
QCOMPARE(threadpool2.activeThreadCount(), reserved);
QCOMPARE(threadpool->activeThreadCount(), 0);
}
QCOMPARE(threadpool2.activeThreadCount(), 0);
QCOMPARE(threadpool->activeThreadCount(), 0);
// releaseThread() can release more than have been reserved
threadpool2.releaseThread();
QCOMPARE(threadpool2.activeThreadCount(), -1);
QCOMPARE(threadpool->activeThreadCount(), 0);
threadpool2.reserveThread();
QCOMPARE(threadpool2.activeThreadCount(), 0);
QCOMPARE(threadpool->activeThreadCount(), 0);
}
// reset limit on global QThreadPool
threadpool->setMaxThreadCount(savedLimit);
}