std::async in 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。所以我遵循Anthony Williams在
中给出的例子http://www.justsoftwaresolutions.co.uk/threading/multithreading-in-c + + 0 x-part-8-futures-and-promises.html
做一个小的改变使它可以编译:
#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;
}
我用
编译clang++——std=c++0x -stdlib=libc++ -lpthread async.cpp
但是,它运行并且总是以核心转储结束:
做东西生命、宇宙和一切的答案都被终止了
我检查核心转储,它显示的堆栈是这样的(我没有得到一个提示)
<>之前#0 0x00007fd0a1a7ba75在raise () from/lib/lib .so.6#1 0x00007fd0a1a7f5c0 in abort () from/lib/lib .so.6#2 0x00007fd0a22a735b在std::exception_ptr::~exception_ptr (this=) at ./src/exception.cpp:130#3 0x0000000000404178无效std::__1::__assoc_state::set_value(int&&) ()#4 0x00000000004051ae in _ZNSt3__119__async_assoc_stateIiNS_12__async_funcIPFivEJEEEE9__executeEv ()#5 0x0000000000404e00在_ZNSt3__114__thread_proxyINS_5tupleIJMNS_19__async_assoc_stateIiNS_12__async_funcIPFivEJEEEEEFvvEPS7_EEEEEPvSC_ ()#6 0x00007fd0a250f9ca在start_thread()从/lib/libpthread.so.0#7 0x00007fd0a1b2e70d在克隆()从/lib/lib .so.6#8 0x0000000000000000 in ??()之前有人知道为什么吗?
我在OS X Lion上运行了您的示例,使用:
clang++ -std=c++0x -stdlib=libc++ async.cpp
程序输出:
doing stuff
The answer to life, the universe and everything is 42
根据moshbear的注释检查libc++的源代码:
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__
}
在我看来,~exception_ptr()
还没有移植到ubuntu 10.04。这是一个在可移植c++中无法实现的低级工具。lib++ abi正在进行创建该级别的无gpl实现的工作。我可以向您保证,libc++abi目前还没有准备好。
在这个低级库上也有一个独立的努力:https://github.com/pathscale/libcxxrt。我不知道这个库的状态,也不知道它是否已经移植到ubuntu。
相关文章:
- 我的神经网络不起作用 [XOR 问题]
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- C++为什么尽管我调用了void函数,它却不起作用
- 为什么在保护模式下继承升级不起作用
- 循环在计数器中不起作用
- 在其他文件中创建类时在 c++ 项目中不起作用
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- 为什么二进制搜索在我的测试中不起作用
- 我的代码中有错误吗?使用BGI图形的C++代码对我不起作用
- 为什么 const std::p air<K,V>& 在 std::map 上基于范围的 for 循环不起作用?
- 带有指定长度字符* 参数的 std::regex_search 在 VS2017 中不起作用?
- Bjarne Stroustrup Book - std_lib_facilities.h - 不起作用(未知类型名称)
- 为什么简单的算术减法在"if"条件下不起作用?
- 为什么Stroustup书中的has_f不起作用
- 你能检查一下为什么在这个代码中从链接列表中删除项目不起作用吗
- 嵌套While循环不起作用(C++问题)
- C++Matching Brackets 2解决方案不起作用
- 为什么这段代码不起作用,我该如何解决?
- std::async in clang 3.0 + libc++ 不起作用?