나는 그것의 Scheduler
클래스를 사용하여 PPL의 원시 스레드의 수를 관리하기 위해 노력하고, 여기에 내 코드입니다 :PPL - 원시 스레드의 수를 구성하는 방법은 무엇입니까?
for (int i = 0; i < 2000; i ++)
{
// configure concurrency count 16 to 32.
concurrency::SchedulerPolicy policy = concurrency::SchedulerPolicy(2, concurrency::MinConcurrency, 16,
concurrency::MaxConcurrency, 32);
concurrency::Scheduler *pScheduler = concurrency::Scheduler::Create(policy);
HANDLE hShutdownEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
pScheduler->RegisterShutdownEvent(hShutdownEvent);
pScheduler->Attach();
//////////////////////////////////////////////////////////////////////////
//for (int i = 0; i < 2000; i ++)
{
concurrency::create_task([]{
concurrency::wait(1000);
OutputDebugString(L"Task Completed\n");
});
}
//////////////////////////////////////////////////////////////////////////
concurrency::CurrentScheduler::Detach();
pScheduler->Release();
WaitForSingleObject(hShutdownEvent, INFINITE);
CloseHandle(hShutdownEvent);
}
SchedulerPolicy
의 사용은 MSDN에서이지만, 그것은 전혀 작동하지 않았다. 위의 코드에서 예상 한 결과는 PPL이 2000 개의 작업을 실행하기 위해 16에서 32 개의 스레드를 실행하지만 사실은 다음과 같습니다.
콘솔 출력 속도를 관찰하면 1 초 이내에 하나의 작업 만 처리됩니다. for
루프를 주석 처리하고 내부 루프 for
의 주석 처리를 제거하려고 시도했지만, 이로 인해 300 개의 스레드가 생성되지만 여전히 올바르지 않습니다. 내가 wait
시간이 길어지면 생성되는 스레드가 훨씬 더 많아집니다.
PPL에서 동시성을 구성하는 올바른 방법은 무엇입니까?
가능한 이유 중 하나는 'WaitForSingleObject' 호출이 완료 될 때까지 각 루프를 차단하여 매번 1 초 동안 루프가 실행되는 것입니다. 그러나 올바른 방법은 무엇입니까? –