Concurrent queue changes in Intel® Threading Building Blocks 2.2

The concurrent queue of Intel® Threading Building Blocks (Intel® TBB) changed significantly from 2.1 to 2.2, for the better, of course :) Member functions that have blocking semantics are dropped and those with potentially thread-unsafe semantics (mostly for debugging purposes) are renamed to indicate it clearly in their names.

(The changes have been incremental, and made available through 2.1 updates, so those who have followed the developer releases must have seen all the changes.)

The changes are three-pronged.  First and foremost is drop of boundedness and the blocking operations.  The 2.1. concurrent queue is of a one-fits-for-all kind.  It is a bounded queue but when initially constructed, it is virtually an unbounded queue and only bounded by available memory in the system.  It has a blocking semantics and push()/pop() make the caller wait until an available slot/item is found.

From 2.2 and on, concurrent queue is an unbounded queue with non-blocking operations only.  The semantic change greatly simplified its implementation.  As a side effect, we were able to move most of the implementation into the header, eliminating most virtual member functions.  It also resulted in a few API changes.

1. Being unbounded means push() always succeed; it never blocks.

2. pop_if_present() is renamed to try_pop() to make its non-blocking semantics clear; pop() which has blocking semantics is dropped in favor of try_pop().

3. Being unbounded makes push_if_not_full()/capacity()/set_capacity() obsolete; they are removed.

4. The size of a concurrent queue becomes non-negative.  size_type is changed to size_t from ptrdiff_t.

The second set of changes has to do with name changes of a few member functions to make their concurrency semantics more clear.  Naturally, all member functions returning an iterator are prefixed with "unsafe_" (i.e., unsafe_begin()/unsafe_end()).  More importantly, size() is renamed to unsafe_size() to signify the fact that with concurrent push/pop, the value may not represent the current size of the queue by the time it returns to the caller.

Lastly, a couple of new constructors were added.  One is a copy constructor which takes another concurrent queue.  And the other is one that takes a couple of InputInterators.

The 2.1 concurrent queue is still supported but with a different name, namely, concurrent_bounded_queue, and with a few name changes.  For example, pop_if_present()/push_if_not_full() become try_pop()/try_push() to align them with those in concurrent_queue.

We strongly encourage Intel® TBB users to rebuild their applications with the new headers.  As always, Intel® TBB supports the backward compatibility -- if you don't want to rebuild your applications your existing binaries built with the 2.1 headers should work with the 2.2 binaries without any problem.  For any reason if you need to recompile your application but don't want to make any source changes, you can do so by compiling your application with TBB_DEPRECATED set.

For more complete information about compiler optimizations, see our Optimization Notice.