4

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 1

1

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.

2
  • 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?
    – Anubis
    Dec 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!
    – n8wrl
    Dec 1, 2016 at 20:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.