As I understand ithat a BlockingCollection uses a non busy wait which is a notify on new items / callback. So I don't understand how it's a blocking but I think im probably mixing blocked threads and blocked access to shared objects?
1 Answer
This is a great explanation:
https://blogs.msdn.microsoft.com/toub/2006/04/12/blocking-queues/
Essentially, the blocking happens when you try to DeQueue something. EnQueue is thread-safe while DeQueue will block (block the thread calling DeQueue) until there is something there to get.
The nice thing is you don't have to care (nor should you care) about how the blocking is implemented.
-
So the consumer is therefore blocking whilst de queueing which stalls the thread? But this doesn't use much cpu it just ties up a thread?– AnubisDec 1, 2016 at 20:00
-
When in doubt, measure - and I suspect blocking won't consume any more than processing the items will be. YMMV!– n8wrlDec 1, 2016 at 20:27