在作业池中使用 iocp

发布于 2024-09-10 12:31:53 字数 478 浏览 1 评论 0原文

当在作业/任务池中使用 iocp 来提供快速工作唤醒时,最小化发送端口信号的开销的最佳方法是什么 - 即不必在每个队列操作中都执行此操作?

<代码> 无效工人() { 同时(1) { for(int spin = 0; spin < 5000; ++spin) while(队列.Count > 0) 队列.PopFront()();

    WaitOnCompletionPort();
}

}

...

queue.PushBack(someWork); // 决定何时向完成端口发出信号但避免每次队列操作都这样做?

例如,在上面的粗略代码草图中,如果您尝试避免每次队列操作都向端口发出信号,则排队的工作和进入的等待之间会出现问题。

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 operation ?

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情魔剑神 2024-09-17 12:31:53

为什么不使用 IOCP 作为队列并将工作项直接发布到其中?这样你就可以免费获得一个线程安全队列,并且可以完全删除你拥有的其他队列?

那么这个问题就会消失;)

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 ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文