Skip to Main Content
Intel Threading Building Blocks
book

Intel Threading Building Blocks

by James Reinders
July 2007
Intermediate to advanced content levelIntermediate to advanced
332 pages
10h 4m
English
O'Reilly Media, Inc.
Content preview from Intel Threading Building Blocks

Iterating over a concurrent_queue for Debugging

The template class concurrent_queue supports STL-style iteration. This support is intended only for debugging, when you need to dump a queue. It provides iterator and const_iterator types. Both follow the usual STL conventions for forward iterators. The iterators go in the forward direction only and are too slow to be very useful in production code. The iteration order is from least recently pushed item to most recently pushed item. If a queue is modified, all iterators pointing to it become invalid and unsafe to use. The snippet of code in Example 5-1 dumps a queue. The operator << is defined for a Foo.

Example 5-1. Concurrent queue listing dump program

concurrent_queue<Foo> q;
...
for(concurrent_queue<Foo>::const_iterator i(q.begin()); i!=q.end( ); ++i ) {
    cout << *i;
}

Warning

The iterators are relatively slow. You should use them only for debugging.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Intel® Xeon Phi™ Coprocessor Architecture and Tools: The Guide for Application Developers

Intel® Xeon Phi™ Coprocessor Architecture and Tools: The Guide for Application Developers

Rezaur Rahman

Publisher Resources

ISBN: 9780596514808Errata Page