std :: async在clang 3.0 + libc ++不工作? [英] std::async in clang 3.0 + libc++ doesn't work?
问题描述
我刚刚在我的ubuntu 10.04上编译和安装了clang + llvm 3.0,还从svn编译并安装了libc ++。由于libc ++中的状态显示线程支持已完成,我想尝试std :: async。于是我按照
由安东尼·威廉姆斯给出的例子
只需进行细微的修改即可编译:
#include< future>
#include< iostream>
int calculate_the_answer_to_LtUaE()
{
return 42;
}
void do_stuff()
{
std :: cout< 做东西< std :: endl;
}
int main()
{
std :: future< int> the_answer = std :: async(calculate_the_answer_to_LtUaE);
do_stuff();
std :: cout<<生活,宇宙和一切的答案是
<< the_answer.get()<< std :: endl;
}
我用
编译clang ++ --std = c ++ 0x -stdlib = libc ++ -lpthread async.cpp
但是,它运行并总是用核心转储完成: p>
做东西
生命,宇宙和一切的答案是Aborted(core dumped)
检查核心转储,它显示堆栈这样(我不会得到一个提示)
#0 0x00007fd0a1a7ba75在raise从/lib/libc.so.6
#2时在0x00007fd0a22a735b的std :: exception_ptr ::〜exception_ptr(此=)/lib/libc.so.6
#1 0x00007fd0a1a7f5c0在中止() ../src/exception.cpp:130
#3 0x0000000000404178在无效的std :: __ 1 :: __ assoc_state :: SET_VALUE(INT &&)()
#4 0x00000000004051ae在_ZNSt3__119__async_assoc_stateIiNS_12__async_funcIPFivEJEEEE9__executeEv()
# 5 0x0000000000404e00从/lib/libc.so.6
从/lib/libpthread.so.0
#_ZNSt3__114__thread_proxyINS_5tupleIJMNS_19__async_assoc_stateIiNS_12__async_funcIPFivEJEEEEEFvvEPS7_EEEEEPvSC_()
#6 0x00007fd0a250f9ca在start_thread()7 0x00007fd0a1b2e70d在克隆() #8 0x0000000000000000 in ?? ()
任何人都知道为什么?
解决方案我在OS X Lion上运行你的例子,使用:
clang ++ -std = c ++ 0x -stdlib = libc ++ async.cpp
程序输出:
$ b b做东西
生命,宇宙和一切的答案是42
根据moshbear的建议检查libc ++的源代码我看到:
exception_ptr ::〜 exception_ptr()_NOEXCEPT
{
#if HAVE_DEPENDENT_EH_ABI
__cxa_decrement_exception_refcount(__ ptr_);
#else
#warning exception_ptr尚未实现
:: abort();
#endif // __APPLE__
}
c $ c>〜exception_ptr()尚未移植到ubuntu 10.04。这是在便携式C ++中不能实现的低级设施。正在 libc ++ abi 上继续开发此级别的无GPL实现。我可以向你保证的libc ++ ABI还没有准备好,此时黄金时间
有也一直在这样低级别的库一个独立的努力,时间:< a href =https://github.com/pathscale/libcxxrt =nofollow> https://github.com/pathscale/libcxxrt 。我不知道这个库的状态,也不知道它是否已被移植到ubuntu。
I just compiled and installed clang+llvm 3.0 on my ubuntu 10.04, and also libc++ from svn. As the status in libc++ shows thread support is complete, I wanted to try std::async. So I follow the example given by Anthony Williams in
And just make minor change to make it compile:
#include <future> #include <iostream> int calculate_the_answer_to_LtUaE() { return 42; } void do_stuff() { std::cout << "doing stuff" << std::endl; } int main() { std::future<int> the_answer=std::async(calculate_the_answer_to_LtUaE); do_stuff(); std::cout<<"The answer to life, the universe and everything is " <<the_answer.get()<<std::endl; }
And I compile with
clang++ --std=c++0x -stdlib=libc++ -lpthread async.cpp
However, it runs and always finish with a core dump:
doing stuff The answer to life, the universe and everything is Aborted (core dumped)
I check the core dump and it shows stack like this (which I don't quite get a hint)
#0 0x00007fd0a1a7ba75 in raise () from /lib/libc.so.6 #1 0x00007fd0a1a7f5c0 in abort () from /lib/libc.so.6 #2 0x00007fd0a22a735b in std::exception_ptr::~exception_ptr (this=) at ../src/exception.cpp:130 #3 0x0000000000404178 in void std::__1::__assoc_state::set_value(int&&) () #4 0x00000000004051ae in _ZNSt3__119__async_assoc_stateIiNS_12__async_funcIPFivEJEEEE9__executeEv () #5 0x0000000000404e00 in _ZNSt3__114__thread_proxyINS_5tupleIJMNS_19__async_assoc_stateIiNS_12__async_funcIPFivEJEEEEEFvvEPS7_EEEEEPvSC_ () #6 0x00007fd0a250f9ca in start_thread () from /lib/libpthread.so.0 #7 0x00007fd0a1b2e70d in clone () from /lib/libc.so.6 #8 0x0000000000000000 in ?? ()Anybody has an idea why?
解决方案I ran your example on OS X Lion, using:
clang++ -std=c++0x -stdlib=libc++ async.cpp
And the program output:
doing stuff The answer to life, the universe and everything is 42
Inspecting the source of libc++ as suggested by moshbear's comment I see:
exception_ptr::~exception_ptr() _NOEXCEPT { #if HAVE_DEPENDENT_EH_ABI __cxa_decrement_exception_refcount(__ptr_); #else #warning exception_ptr not yet implemented ::abort(); #endif // __APPLE__ }
It appears to me that
~exception_ptr()
has not been ported to ubuntu 10.04. This is a low-level facility not implementable in portable C++. Work on creating a GPL-free implementation of this level is ongoing at libc++abi. I can assure you that libc++abi is not ready for prime time at this time.There has also been an independent effort at this low-level library at: https://github.com/pathscale/libcxxrt . I do not know the status of this library nor whether it has been ported to ubuntu.
这篇关于std :: async在clang 3.0 + libc ++不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文