在該柱的底部的代碼編譯好,但是當該命令被給予在鐺線程支持++ 3.3 C++ 11
clang++ -std=c++11 -pthread -s -O3 -DNDEBUG source.cpp -o source
二進制生成與
$ clang++ -v
clang version 3.3 (trunk 168461)
Target: x86_64-unknown-linux-gnu
Thread model: posix
無用的二進制總是生成此
terminate called after throwing an instance of 'std::system_error'
what(): Operation not permitted
Aborted (core dumped)
我不明白的是:
- 爲什麼我需要鏈接POSIX線程庫如果C++ 11在標準中包含線程模型,爲什麼標記
-std=c++11
還不夠? - 如果鐺++支持
-pthread
與否,根據我讀它應該支持並行線程
感謝。
#include <iostream>
#include <thread>
void f()
{
std::cout << "Hello World\n";
}
int main()
{
std::thread t(f);
t.join();
}
你應該使用鐺時使用的libC++標準庫。只需將'-stdlib = libC++'添加到您的編譯器參數中即可。 – inf
@bamboon是的,我已經要求他嘗試。 – Ali
如果您使用libstdC++(不是libC++),您是否嘗試在命令行中添加'-D__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 -D__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 -D__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 -D__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8'?檢查它是否改善了這種情況。背景資料[here](http://llvm.org/bugs/show_bug.cgi?id=12730)。 –