本文整理汇总了C++中ThreadPool::GetWork方法的典型用法代码示例。如果您正苦于以下问题:C++ ThreadPool::GetWork方法的具体用法?C++ ThreadPool::GetWork怎么用?C++ ThreadPool::GetWork使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ThreadPool
的用法示例。
在下文中一共展示了ThreadPool::GetWork方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
unsigned int __stdcall ThreadPool::Execute(void* _args)
{
// TODO - implement your own version
//return ExecuteSolution(_args);
ThreadPool* self = (ThreadPool*)_args;
bool run = true; // local run bool for completeing last bit of work
WorkerThread* workerPtr = nullptr; //worker thread
int work = 0; // amount of work left in the queue
while( run )
{
workerPtr = nullptr;
self->GetWork( &workerPtr );
if( workerPtr != nullptr )
{
workerPtr->DoWork();
workerPtr->workDone.Post();
}
self->runMutex.Lock();
run = self->run;
self->runMutex.Unlock();
self->queueMutex.Lock();
work = self->workers.size();
self->queueMutex.Unlock();
if( work > 0 )
run = true;
}
/*self->runMutex.Lock();
if(self->run == false)
{
while( self->workers.size() > 0 )
{
WorkerThread* workerPtr = nullptr;
self->GetWork( &workerPtr );
if( workerPtr != nullptr )
{
workerPtr->DoWork();
workerPtr->workDone.Post();
}
else
break;
}
}
self->runMutex.Unlock();*/
return self->shutdownType;
}