Std :: async in clang 3.0 + libc ++ not working?

I just compiled and installed clang + llvm 3.0 on my ubuntu 10.04 as well as libC ++ from svn. Since the status in libC ++ shows thread support, I wanted to try std :: async. Therefore I follow the example of Anthony Williams in

http://www.justsoftwaresolutions.co.uk/threading/multithreading-in-c++0x-part-8-futures-and-promises.html

And just make small changes to compile it:

#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 will compile

clang ++ --std = C ++ 0x -stdlib = libC ++ -lpthread async.cpp

However, it starts and always ends with a core dump:

do things The answer to life, the universe and everything is canceled (the core is reset)

I check the core dump and it shows such a stack (which I did not quite understand)

  # 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 ??  ()

Does anyone have an idea why?

+6
source share
1 answer

I ran your example on OS X Lion using:

 clang++ -std=c++0x -stdlib=libc++ async.cpp 

And the output of the program:

 doing stuff The answer to life, the universe and everything is 42 

Checking the source of libC ++, as suggested by moshbear 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 seems to me that ~exception_ptr() not been ported to ubuntu 10.04. This is a low-level tool not implemented in portable C ++. Work on creating a GPL-free implementation of this level continues in lib ++ abi . I can assure you that libC ++ abi is currently not ready for prime time.

This low-level library also had independent efforts: https://github.com/pathscale/libcxxrt . I do not know the status of this library and have not been ported to ubuntu.

+7
source

Source: https://habr.com/ru/post/903244/


All Articles