0

I install the threading building blocks(http://threadingbuildingblocks.org/ver.php?fid=174) in centos in directory /home/is_admin/tbb40_233oss/

This is my code:

#include "tbb/concurrent_queue.h" 
#include <iostream> 
using namespace std; 
using namespace tbb; 
int main() { 
    concurrent_queue<int> queue; 
    for( int i=0; i<10; ++i ) 
        queue.push(i); 
    for( concurrent_queue<int>::const_iterator i(queue.begin()); 
i!=queue.end(); ++i ) 
        cout << *i << " "; 
    cout << endl; 
    return 0; 
}

I compile the code using this command:

g++ test_concurrent_queue.cpp -I/home/is_admin/tbb40_233od/linux_intel64_gcc_cc4.1.2_libc2.5_kernel2.6.18_release -ltbb -o tcq

but it gives this error:

class tbb::strict_ppl::concurrent_queue<int, tbb::cache_aligned_allocator<int> > has no member named begin

class tbb::strict_ppl::concurrent_queue<int, tbb::cache_aligned_allocator<int> > has no member named end

I cann't find out why? Anybody have tbb experience can help me?

Treper
  • 3,539
  • 2
  • 26
  • 48

1 Answers1

2

EDIT:

The documentation you used is outdated and no longer works with concurrent_queue. The rest of my answer still stands.


Because concurrent_queue has no begin or end method: http://threadingbuildingblocks.org/files/documentation/a00134.html

There is an unsafe_begin and an unsafe_end method, named that way because you should only use them if your queue isn't being used by more than one thread (that is, they are unsafe to use in a multithreaded environment).

The general way to run through a queue is to pop elements until it's empty:

int i;
while(queue.try_pop(i)) // as long as you can pop, pop.
    cout << i << " "; 
Etienne de Martel
  • 34,692
  • 8
  • 91
  • 111
  • Do you mean I have to use the concurrent_bounded_queue?The code is the sample code of threadingbuildingblocks.org http://cache-www.intel.com/cd/00/00/30/11/301114_301114.pdf#page=61 – Treper Apr 19 '12 at 06:15
  • Hm, I might have missed something. The answer I gave was for `tbb::strict_ppl::concurrent_queue`, which is what your compiler thinks `concurrent_queue` refers to. Looks like there's another `concurrent_queue` class with a different interface. – Etienne de Martel Apr 19 '12 at 06:21
  • @Greper: The document you linked to is from 2007. There is newer documentation [here](http://threadingbuildingblocks.org/documentation.php). – Jesse Good Apr 19 '12 at 06:24
  • @Jesse Yeah, that he used outdated documentation was my best guess. – Etienne de Martel Apr 19 '12 at 06:26