我不明白我在这里做错了什么。这个非常短的程序:
#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;
}
编译时它可以完美地工作gcc (4.7.2)
:
$ g++ -ggdb -std=c++11 -pthread -o clang_thread_test clang_thread_test.cpp
$ ./clang_thread_test
Hello World
但是,当编译时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
这有已知的原因吗?我唯一发现的东西与失踪有关-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
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53841
计时线程错误修复:
linux error: no matching constructor for initialization of 'duration'
使用建议的修复:
- 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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)