2

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

dimba
  • 26,717
  • 34
  • 141
  • 196

6 Answers6

1

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

Michael Foukarakis
  • 39,737
  • 6
  • 87
  • 123
1

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
  • 66,628
  • 14
  • 133
  • 155
0

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
  • 204,818
  • 23
  • 294
  • 489
0

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

Look up Interlocked Singly Linked Lists

Goz
  • 61,365
  • 24
  • 124
  • 204
0

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
  • 3,364
  • 25
  • 33
0

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