开发者

Using iocp in a job pool

开发者 https://www.devze.com 2023-01-07 19:34 出处:网络
When using iocp in a job/task pool to provide fast worker wake ups what is the best way to minimise the overhead of signalling the port - ie not having to do it every queue operation?

When using iocp in a job/task pool to provide fast worker wake ups what is the best way to minimise the overhead of signalling the port - ie not having to do it every queue operation?

void Worker() { while(1) { for(int spin = 0; spin < 5000; ++spin) while(queue.Count > 0) queue.PopFront()();

    WaitOnCompletionPort();
}

}

...

queue.PushBack(someWork); // decide when to signal completion port but avoid doing it every queue o开发者_JAVA百科peration ?

For example in the above rough code sketch there is a problem between work being queued and the wait being entered if you try and avoid signalling the port every queue operation.


Why don't you use the IOCP as your queue and post your work items directly to it? That way you get a thread safe queue for free and can completely remove the other queue you have?

This question would then go away ;)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号