For single-producer, single-consumer should I use a BlockingCollection or a ConcurrentQueue?

Posted by Jonathan Allen on Stack Overflow See other posts from Stack Overflow or by Jonathan Allen
Published on 2010-05-26T20:38:02Z Indexed on 2010/05/26 20:41 UTC
Read the original article Hit count: 288

For single-producer, single-consumer should I use a BlockingCollection or a ConcurrentQueue?

Concerns: * My goal is to pull up to 100 items at a time and send them as a batch to the next step. * If I use a ConcurrentQueue, I have to manually cause it to go asleep when there is no work to be done. Otherwise I waste CPU cycles on spinning. * If I use a BlockingQueue and I only have 99 work items, it could indefinitely block until there the 100th item arrives.

http://msdn.microsoft.com/en-us/library/system.collections.concurrent.aspx

© Stack Overflow or respective owner

Related posts about multithreading

Related posts about concurrency