2012-04-19 80 views
0

我在目录CentOS的安装线程构建模块(http://threadingbuildingblocks.org/ver.php?fid=174)/家庭/ is_admin/tbb40_233oss/为什么这个tbb程序无法编译?

这是我的代码:

#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; 
} 

我编译代码使用这个命令:

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 

,但它给出了这样的错误:

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 

我无法找出原因?任何人有tbb的经验可以帮助我吗?

回答

2

编辑:

您使用的文档已经过时,不再与concurrent_queue工作。我的答案的其余部分仍然存在。


因为concurrent_queue没有beginend方法: http://threadingbuildingblocks.org/files/documentation/a00134.html

有一个unsafe_beginunsafe_end方法,这样的命名方式,因为你只能使用他们,如果你的队列没有使用更多而不是一个线程(也就是说,它们是不安全的在多线程环境中使用)。

通过队列运行的一般方法是流行元素,直到它是空的?

int i; 
while(queue.try_pop(i)) // as long as you can pop, pop. 
    cout << i << " "; 
+0

你的意思是我必须使用concurrent_bounded_queue的代码是threadingbuildingblocks.org HTTP的示例代码:// cache.www.intel.com/cd/00/00/30/11/301114_301114.pdf#page=61 – Treper 2012-04-19 06:15:41

+0

嗯,我可能错过了一些东西。我给出的答案是'tbb :: strict_ppl :: concurrent_queue',这是你的编译器认为'concurrent_queue'引用的内容。看起来像另一个'concurrent_queue'类具有不同的接口。 – 2012-04-19 06:21:03

+0

@Greper:您链接的文档来自2007年。有更新的文档[此处](http://threadingbuildingblocks.org/documentation.php)。 – 2012-04-19 06:24:42