Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why is concurrent_queue non-blocking?

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?

like image 666
eli Avatar asked Oct 13 '10 14:10

eli


People also ask

What is a non-blocking process?

Non-Blocking: It refers to the program that does not block the execution of further operations. Non-Blocking methods are executed asynchronously. Asynchronously means that the program may not necessarily execute line by line.

What is non-blocking queue?

Unlike a LinkedBlockingQueue, a ConcurrentLinkedQueue is a non-blocking queue. Thus, it does not block a thread once the queue is empty. Instead, it returns null. Since its unbounded, it'll throw a java.

What is non-blocking thread?

A task (thread) is non-blocking when it doesn't cause other tasks (threads) to wait until the task is finished.

What is blocking and non-blocking queue?

Blocking vs Non-Blocking QueueThe producers will wait for available capacity before adding elements, while consumers will wait until the queue is empty. In those cases, the non-blocking queue will either throw an exception or return a special value, like null or false.


2 Answers

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


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.


(a) Arch is the architect of Threading Building Blocks.

like image 196
paxdiablo Avatar answered Sep 18 '22 01:09

paxdiablo


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.

like image 23
Michael Goldshteyn Avatar answered Sep 18 '22 01:09

Michael Goldshteyn