views:

32

answers:

1

.NET for added new concurrency features under System.Collection.Concurrent and some synchronization classes. Is there any good sample for single producer - single consumer pattern using these feature ? (Actually I will add a circular buffer pattern to it if it already doesn't implement it as the shared buffer)

A: 

The new type BlockingCollection<T> (see MSDN) implements a producer/consumer pattern. It can be accessed by multiple producers/consumers concurrently, but it will work perfectly fine with a single producer and consumer too.

Tomas Petricek
I read about it but there's no good sample out there, try google with "producer consumer .net 4.0". Also it's not flexible enough. For example what if consumer wants to notify the end of operation if sending fails? What if I don't want wake-up producer until half of buffer (BlockingCollection) gets empty ?
Xaqron