mag*_*eta 3 c++ multithreading clang c++11
我无法弄清楚我在这里做错了什么.这个非常短的计划:
#include <iostream>
#include <string>
#include <atomic>
#include <thread>
using namespace std;
int
main(int argc, char ** argv)
{
thread foo( []() {
cout << "Hello World" << endl;
return 0;
} );
foo.join();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译时它完美地工作gcc (4.7.2)
:
$ g++ -ggdb -std=c++11 -pthread -o clang_thread_test clang_thread_test.cpp
$ ./clang_thread_test
Hello World
Run Code Online (Sandbox Code Playgroud)
但是,使用clang (3.2; x86_64-pc-linux-gnu; thread model: posix)
它编译时无法执行:
$ clang++ -ggdb -std=c++11 -pthread -o clang_thread_test clang_thread_test.cpp
$ ./clang_thread_test
pure virtual method called
terminate called without an active exception
Aborted
Run Code Online (Sandbox Code Playgroud)
有这个已知的原因吗?我发现的唯一的事情与丢失-pthread switch
或未使用有关libc++
.据我所知,后者只与苹果系统有关.
确认这有效:
clang++ --std=c++11 -pthread -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
Run Code Online (Sandbox Code Playgroud)
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53841
计时线程错误修复:
linux error: no matching constructor for initialization of 'duration'
Run Code Online (Sandbox Code Playgroud)
使用建议的修复:
- const chrono::nanoseconds __delta = __atime - __c_entry;
- const __clock_t::time_point __s_atime = __s_entry
+ __delta; + const auto __delta = __atime - __c_entry;
+ const auto __s_atime = __s_entry
+ __delta; in file condition_variable
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3082 次 |
最近记录: |