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.
Read now
Unlock full access