2012-04-19 55 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