用例:在C ++中创建线程池,并将工作分配给所有线程。我想在来自threadpool的线程完成其工作时触发事件。
但我不知道当线程池中的线程完成其工作时如何触发事件。
示例:
void ThreadPoolImpl::InitThreadPool(){
pool = CreateThreadpool(NULL);
if (pool == NULL)
{
//Log("Could not create a thread pool!");
return;
}
InitializeThreadpoolEnvironment(&environment);
cleanupGroup = CreateThreadpoolCleanupGroup();
if (cleanupGroup == NULL)
{
//Log("Could not create a thread pool cleanup group!");
}
SetThreadpoolCallbackPool(&environment, pool);
SetThreadpoolCallbackCleanupGroup(&environment, cleanupGroup, NULL);}
void ThreadPoolImpl::RunThreads(int const iThreadCount)
{
dwThreadCount = iThreadCount;
if (dwThreadCount == 0)
{
dwThreadCount = DEFAULT_THREAD_COUNT;
}
SetThreadpoolThreadMaximum(pool, dwThreadCount);
SetThreadpoolThreadMinimum(pool, MIN_THREAD_COUNT);
work = CreateThreadpoolWork(workcallback,NULL,&environment);
if (NULL == work) {
_tprintf(_T("CreateThreadpoolWork failed. LastError: %u\n"),
GetLastError());
}
SubmitThreadpoolWork(work);//Want to trigger an event for each thread in thread pool
}
帮我解决这个问题。
提前致谢。