July 2007
Intermediate to advanced
332 pages
10h 4m
English
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;
}The iterators are relatively slow. You should use them only for debugging.