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


C++ ThreadPool::FetchWork方法代码示例

本文整理汇总了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;
}
开发者ID:CSRedRat,项目名称:CodeXL,代码行数:53,代码来源:ThreadPool.cpp


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