阻塞队列线程生产者/消费者为Win32 / C [英] Blocking queue for thread producer/consumers for win32/C

查看:136
本文介绍了阻塞队列线程生产者/消费者为Win32 / C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想,以取代自定义队列某个线程的通信,生产商目前
PostThreadMessage,消费者正在使用WaitForSingleObject的/的PeekMessage。

I'm trying to replace some thread communication with a custom queue, producer is currently using PostThreadMessage, consumer is using WaitForSingleObject/PeekMessage.

<一个href=\"http://www.justsoftwaresolutions.co.uk/threading/implementing-a-thread-safe-queue-using-condition-variables.html\" rel=\"nofollow\">http://www.justsoftwaresolutions.co.uk/threading/implementing-a-thread-safe-queue-using-condition-variables.html会是什么,我需要,但也提振C ++是不是一种选择。

http://www.justsoftwaresolutions.co.uk/threading/implementing-a-thread-safe-queue-using-condition-variables.html would be what I needed, but boost nor C++ is not an option.

不希望重新实现车轮,没有人有这样的用C语言实现一个队列?

Not wanting to reimplement the wheel, does anyone have such a queue implemented in C ?

推荐答案

使用的IO完成端口(见的此处)作为您的队列中;它们并不需要被只是有关I / O操作,并且很容易使用和执行得非常好,由于在内核可以被设置,以限制在线程池运行线程数的方式。

Use an IO Completion Port (see here) as your queue; they don't need to be just related to I/O operations and are very easy to use and perform very well due to the way the kernel can be set to limit the number threads that run in your thread pool.

基本上你叫 PostQueuedCompletionStatus()将项目队列和则GetQueuedCompletionStatus()来把他们赶走。您不必担心同步等。

Basically you call PostQueuedCompletionStatus() to put items on the queue and GetQueuedCompletionStatus() to take them off. You don't need to worry about synchronisation etc.

如果你得到它的工作,那么需要一点点更多的帮助,你可以看看我的免费高性能服务器架构,其中包括了很多IOCP code,包括未以任何方式与I / O相关的一个独立的线程池。请注意,这是在C ++中,但它应该给你的C API是如何挂在一起是一个好主意。

If you need a little more help in getting it to work then you could take a look at my free high performance server framework which includes quite a lot of IOCP code, including a stand alone thread pool that isn't related in any way to I/O. Note that this is in C++ but it should give you a good idea of how the C API hangs together.

这篇关于阻塞队列线程生产者/消费者为Win32 / C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆