本文整理汇总了C++中WorkerThread类的典型用法代码示例。如果您正苦于以下问题:C++ WorkerThread类的具体用法?C++ WorkerThread怎么用?C++ WorkerThread使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WorkerThread类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: m_NumLocalJobsActive
// CONSTRUCTOR
//------------------------------------------------------------------------------
JobQueue::JobQueue( uint32_t numWorkerThreads ) :
m_NumLocalJobsActive( 0 ),
m_DistributableAvailableJobs( 1024, true ),
m_DistributableJobsMemoryUsage( 0 ),
m_DistributedJobsRemote( 1204, true ),
m_DistributedJobsLocal( 128, true ),
m_DistributedJobsCancelled( 128, true ),
m_CompletedJobs( 1024, true ),
m_CompletedJobsFailed( 1024, true ),
m_CompletedJobs2( 1024, true ),
m_CompletedJobsFailed2( 1024, true ),
m_Workers( numWorkerThreads, false )
{
WorkerThread::InitTmpDir();
for ( uint32_t i=0; i<numWorkerThreads; ++i )
{
// identify each worker with an id starting from 1
// (the "main" thread is considered 0)
uint32_t threadIndex = ( i + 1 );
WorkerThread * wt = FNEW( WorkerThread( threadIndex ) );
wt->Init();
m_Workers.Append( wt );
}
}
示例2: while
ThreadPool::~ThreadPool( )
{
// --------------------------------------------------------------
// Request Termination of all worker threads.
// --------------------------------------------------------------
m_mList.lock();
WorkerThreadList list = m_lstThreads;
m_mList.unlock();
WorkerThreadList::iterator it = list.begin();
for (; it != list.end(); ++it)
{
if (*it != NULL)
(*it)->RequestTerminate();
}
while (!list.empty())
{
WorkerThread *pThread = list.front();
list.pop_front();
if (pThread != NULL)
{
pThread->wait();
delete pThread;
}
}
}
示例3: WorkerThread
void Controller::startWorkInAThread()
{
WorkerThread *workerThread = new WorkerThread(this);
connect(workerThread, &WorkerThread::resultReady, this, &Controller::handleResults);
connect(workerThread, &WorkerThread::finished, workerThread, &QObject::deleteLater);
workerThread->start();
}
示例4: l
/*!
* \brief WorkerThreadPool::findResponsiveThread
* \return
*/
WorkerThread *WorkerThreadPool::findResponsiveThread()
{
QMutexLocker l(&threadListMutex);
if(idleThreads.size()) {
WorkerThread* wt = idleThreads.takeFirst();
qDebug()<<"[Main] Using Thread "<<wt->threadId()<<" from idle List";
return wt;
} else {
qDebug()<<"[Main] No Idle Threads trying to find a responsive one";
int myThread = -1;
for(int i = 0; i < threads.size(); i++) {
WorkerRunnable::Load load = threads.at(i)->workLoad();
if(load == WorkerRunnable::Low) {
myThread = i;
break;
} else if(load == WorkerRunnable::Medium && myThread == -1) {
myThread = i;
continue;
}
}
if(myThread >= 0) {
//move the thread to the back, so it will be picked later the next time
WorkerThread* t = threads.takeAt(myThread);
threads.append(t);
return t;
}
//we did not find a thread , enqueue it
}
return 0;
}
示例5: run_normal
/** \brief The normal thread run function.
*
* The function to be started by normal workers.
*/
static void run_normal()
{
boost::mutex::scoped_lock scope(mut);
boost::thread::id tid = boost::this_thread::get_id();
WorkerThread* thr = (*threads.find(tid)).second.get();
while(!quitting)
{
if(inner_run_important(scope))
{
continue;
}
if(inner_run_normal(scope))
{
continue;
}
wake_normal();
workers_active.remove(thr);
workers_sleeping.addLast(thr);
thr->suspend(scope);
}
// Remove from active workers before exiting.
workers_active.remove(thr);
}
示例6: main
int main(int argc, char **args)
{
WorkerThread wt;
wt.start();
wt.wait();
return 0;
}
示例7: ThreadMain
unsigned WINAPI WorkerThread::ThreadMain(LPVOID thread){
WorkerThread* workerThread = (WorkerThread*)thread;
workerThread->run();
return 0;
}
示例8: fprintf
/**
* Called by the monitor thread to harvest idle threads.
*/
void
ThreadPool::harvestSpareWorkers() {
PoolObject *po;
int toFree = 0;
cond.lock();
if (stopThePool) {
cond.unlock();
return;
}
if ((currentThreadCount - currentThreadsBusy) > maxSpareThreads) {
toFree = currentThreadCount -
currentThreadsBusy -
maxSpareThreads;
if (debug)
fprintf(stdout, "ThreadPool.harvestSpareWorkers: Freeing %d threads because they are idle\n",
toFree);
for (int i = 0 ; i < toFree ; i++) {
po = (PoolObject *) idleThreads.pop();
WorkerThread *c = po->getThread();
c->terminate();
currentThreadCount --;
}
if (debug)
fprintf(stdout, "ThreadPool.harvestSpareWorkers: Current Thread Count = %d\n",
currentThreadCount);
}
cond.unlock();
}
示例9: tDebug
QDebug tDebug()
{
WorkerThread* t = qobject_cast<WorkerThread*>(QThread::currentThread());
if(t)
return qDebug()<<"["<<t->threadId()<<"]";
return qDebug();
}
示例10: JobCleanup
// Called by a worker thread on return from a job.
void WorkerThread::JobCleanup(void *param)
{
WorkerThread *worker = (WorkerThread *)param;
(void) pthread_mutex_lock(&(worker->m_worker_mutex));
if (worker->m_worker_flags & WORKER_WAIT)
worker->NotifyWaiters();
}
示例11: L_FUNC
void Task::startWorkerThread(const QString &id)
{
L_FUNC(QString("id='%1'").arg(id));
WorkerThread *workerThread = new WorkerThread(id, this);
connect(workerThread, SIGNAL(resultReady(const QString&)), this, SLOT(slotResultReady(const QString&)));
connect(workerThread, SIGNAL(finished()), workerThread, SLOT(deleteLater()));
workerThread->start();
}
示例12: wakeUpOneThread
void TaskScheduler::wakeUpOneThread()
{
WorkerThread* thread = mIdleThreads.pop();
if(thread)
{
SCHEDULER_DEBUG("wakeUpOneThread -- thread #" << thread->getThreadId() << " -- #" << thread->getDoWorkEvent()->getHandle());
thread->getDoWorkEvent()->fire();
}
}
示例13: WorkerThread
void *Thread_Func(void *arg)
{
WorkerThread *worker = new WorkerThread((RequestQueue *)arg);
signal(SIGTERM, cleanExit);
signal(SIGINT, cleanExit);
signal(SIGPIPE, SIG_IGN);
worker->mainloop();
pthread_exit(NULL);
}
示例14: WorkerThread
void MainWindow::on_learnDicOkBtn_clicked()
{
ui->learnDicOkBtn->setEnabled(false);
ui->saveCfBtn->setEnabled(false);
WorkerThread *workerThread = new WorkerThread();
connect(workerThread, SIGNAL(resultReady()), this, SLOT(updateSisrButtons()));
connect(workerThread, SIGNAL(exceptionOccurs()), this, SLOT(sisrExceptionOccurs()));
workerThread->start();
}
示例15:
// MainWrapper
//------------------------------------------------------------------------------
/*static*/ uint32_t WorkerThread::ThreadWrapperFunc( void * param )
{
WorkerThread * wt = reinterpret_cast< WorkerThread * >( param );
s_WorkerThreadThreadIndex = wt->m_ThreadIndex;
CreateThreadLocalTmpDir();
wt->Main();
return 0;
}