本文整理汇总了C++中ThreadPool::FetchWork方法的典型用法代码示例。如果您正苦于以下问题:C++ ThreadPool::FetchWork方法的具体用法?C++ ThreadPool::FetchWork怎么用?C++ ThreadPool::FetchWork使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ThreadPool
的用法示例。
在下文中一共展示了ThreadPool::FetchWork方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ThreadExecute
//
// ThreadPool's thread start routine
// - All the worker threads will start with this routine
// - the parameter passed to this thread start routine is "WorkThreadParam"
// It has
// threadWorkFunction :- thread work function;
// threadWorkParam :- thread param for the "threadWorkFunction"
// tPool :- thread pool object itself
//
DWORD WINAPI ThreadPool::ThreadExecute(LPVOID param)
{
osNameThreadInDebugger(osGetCurrentThreadId(), "PoolThread");
PrdWorkUnit work;
if (NULL == param)
{
OS_OUTPUT_DEBUG_LOG(L"Invalid arg for worker thread", OS_DEBUG_LOG_ERROR);
return (DWORD)E_INVALIDARG;
}
WorkThreadParam* wParam = (WorkThreadParam*)param;
ThreadPool* tp = (ThreadPool*)wParam->tPool;
OS_OUTPUT_FORMAT_DEBUG_LOG(OS_DEBUG_LOG_DEBUG, L"Thread (%d) Created", GetCurrentThreadId());
// the worker cannot be assigned empty work..
// ThreadPool::fetchwork() will return false on DUMMY work;
// DUMMY work is used to request the thread to terminate.
while (tp->FetchWork(&work))
{
wParam->threadWorkFunction(wParam->threadWorkParam, (void*)&work);
tp->m_workQueue->SetWorkStatusComplete();
}
// This is to cleanup the Dummy work..
// Is there a way to verify that we have received dummy work ?
if (tp->m_workQueue->IsWorkPending())
{
tp->m_workQueue->SetWorkStatusComplete();
}
// If still some work is pending, emit a warning message
if (tp->m_workQueue->IsWorkPending())
{
OS_OUTPUT_DEBUG_LOG(L"Warning: Still some work is pending in the workqueue or work-in-progress in some other thread...\n",
OS_DEBUG_LOG_DEBUG);
}
OS_OUTPUT_FORMAT_DEBUG_LOG(OS_DEBUG_LOG_DEBUG, L"Return from the thread (%d)", GetCurrentThreadId());
return 0;
}