views:

142

answers:

6

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

+1  A: 

There is, it's called a mutex. (Lockable for boost..)

Michael Foukarakis
A: 

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.

David Rodríguez - dribeas
A: 

If you are using windows then microsoft provide code from a multiple producer multiple consumer lockless list.

Look up Interlocked Singly Linked Lists

Goz
If you want in-order consumption, then SLIST is limited to multiple-producer / single-consumer.
Adisak
Should note that "Interlocked Singly Linked Lists" is 32bit only.
ceretullis
Not true MS have provided a 128-bit version via "cmpxchg16b"
Goz
A: 

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

Chris Bednarski
A: 

If the objects are of POD type, you can write them to a socketpair on Linux and get the behaviour you expect.

Matthew Herrmann
A: 

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

Anthony Williams