views:

117

answers:

4

In the concurrency runtime introduced in VS2010, there is a concurrent_queue class. It has a non blocking try_pop() function.
Similar in Intel Thread Building Blocks (TBB), the blocking pop() call was removed when going from version 2.1 to 2.2.

I wonder what the problem is with a blocking call. Why was it removed from TBB? And why is there no blocking concurrent_queue?

I'm in a situation where I need a blocking concurrent queue, and I don't want a busy wait. Apart from writing a queue myself, is there another possibility in the concurrency runtime?

+13  A: 

From a comment from Arch Robison (it doesn't get much more "horse's mouth" than that):

PPL's concurrent_queue has no blocking pop, hence neither does tbb::strict_ppl::concurrent_queue. The blocking pop is available in tbb::concurrent_bounded_queue.

The design argument for omitting blocking pop is that in many cases, the synchronization for blocking is provided outside of the queue, in which case the implementation of blocking inside the queue becomes unnecessary overhead. On the other hand, the blocking pop of the old tbb::concurrent_queue was popular among users who did not have outside synchronization. So we split the functionality. Use cases that do not need blocking or boundedness can use the new tbb::concurrent_queue, and use cases that do need it can use tbb::concurrent_bounded_queue.

paxdiablo
+4  A: 

If you need a blocking pop without a busy wait, you need a method of signaling. This implies synchronization between pusher and poper and the queue is no longer without (expensive) synchronization primitives. You basically get a normal synchronized queue with a condition variable being used to notify poppers of pushes, which is not in the spirity of the concurrent_* collections.

Michael Goldshteyn
+1  A: 

There is no situation, from the queue's standpoint, that it should need to block for an insert or remove. The fact that you may need to block and wait for an insert is immaterial.

You can achieve the functionality you desire by using a condition variable, or a counting semaphore, or something along those lines (whatever your specific API provides). Your trouble isn't with blocking/non-blocking; it sounds like a classic producer-consumer.

San Jacinto
+1  A: 

The question was if there was another option in the Concurrency Runtime that provides blocking queue functionality because concurrent_queue does not and there is one in VS2010.

Arch's comment is of course completely correct, blocking queues and unblocking queues are separate use cases and this is why they are different in VS2010 and in TBB.

In VS2010 you can use the template class unbounded_buffer located in , the appropriate methods are called enqueue and dequeue.

-Rick

Rick