开发者

Synchronized list for threaded application

开发者 https://www.devze.com 2022-12-14 05:36 出处:网络
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 qu

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消