I'm using active object design pattern.
I need a list, which holds user defined objects of the same t开发者_如何学Goype. 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).
There is, it's called a mutex. (Lockable for boost..)
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
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.
If you are using windows then microsoft provide code from a multiple producer multiple consumer lockless list.
Look up Interlocked Singly Linked Lists
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
If the objects are of POD type, you can write them to a socketpair on Linux and get the behaviour you expect.
精彩评论