Reputation: 4898
I have a bunch of threads producing objects (e.g. strings) and a single thread consuming batch of objects (e.g. serializing them and sending yo a remote server).
I want producers to be able to pish data as fast as possible. They should never lock because of other producers, not even by the consumer. Is this possible? How?
Upvotes: 0
Views: 432
Reputation: 113462
You can use a BlockingCollection, which by default wraps a ConcurrentQueue
.
BlockingCollection is a thread-safe collection class that provides the following features:
An implementation of the Producer-Consumer pattern.
Concurrent adding and taking of items from multiple threads.
Upvotes: 1