Synchronized list for threaded application

1.7k views Asked by At

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

6

There are 6 answers

0
Matthew Herrmann On

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

0
Michael Foukarakis On

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

0
David Rodríguez - dribeas On

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.

3
Goz On

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

Look up Interlocked Singly Linked Lists

0
Chris Bednarski On

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

0
Anthony Williams On

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