线程应用程序的同步列表
我正在使用主动对象设计模式。
我需要一个列表,其中包含相同类型的用户定义对象。多个写入者将对象推送到列表中,读取者可以定时在队列上等待。
我知道我可以包装一个STL列表,但也许boost中有现成的解决方案?我就是找不到它。
UPD:
该应用程序在 Linux (RHEL 5.3) 上运行。
I'm using active object design pattern.
I need a list, which holds user defined objects of the same type. Multiple writers push the objects to the list and readers can wait on the queue in a timed manner.
I know I can wrap an STL list, but maybe there ready solution in boost? I just can't find it.
UPD:
The application runs on Linux (RHEL 5.3).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
有,它称为互斥体。 (可锁定以提升..)
There is, it's called a mutex. (Lockable for boost..)
我在我的博客上写了一篇关于如何使用 boost 编写线程安全队列的文章
: -condition-variables.html" rel="nofollow noreferrer">http://www.justsoftwaresolutions.co.uk/threading/implementing-a-thread-safe-queue-using-condition-variables.html
I wrote an article about how to write a thread-safe queue using boost over on my blog:
http://www.justsoftwaresolutions.co.uk/threading/implementing-a-thread-safe-queue-using-condition-variables.html
没有现成的解决方案,但您会找到您需要的砖块。查看 boost::thread 库或您当前使用的线程库中的文档,了解如何授予独占访问权限。通常它是通过某种
mutex
实现的。There is no already built solution, but you will find the bricks you need. Take a look at the boost::thread library, or the docs in the threading library you are currently using to know how exclusive access is granted. Usually it is through a
mutex
of some kind.如果您使用的是 Windows,那么微软会提供来自多个生产者多个消费者无锁列表的代码。
查找互锁单链表
If you are using windows then microsoft provide code from a multiple producer multiple consumer lockless list.
Look up Interlocked Singly Linked Lists
这种类型的容器称为有界/阻塞队列,
请尝试此代码项目页面ac# 示例
Joe Duffy 所著的《Windows 上的并发编程》一书很好地解释了整个概念
This type of container is called a bounded/blocking queue
Try this codeproject page for a c# example
The whole concept is explained very well in a book 'Concurrent Programming on Windows' by Joe Duffy
如果对象是 POD 类型,您可以将它们写入 Linux 上的套接字对并获得您期望的行为。
If the objects are of POD type, you can write them to a socketpair on Linux and get the behaviour you expect.