Segmention fault mit std::async()



  • Hallo zusammen,

    ich versuche derzeit, mit Hilfe von

    std::async()
    

    mehrere Tasks gleichzeitig laufen zu lassen.
    Der Code ohne Nebenlaeufigkeit:

    class Dimer {/*...*/};
    class Monomer {/*...*/};
    
    string dimername{};
    vector<string> monomers{};
    vector<Monomer> mons{};
    
    Dimer dimer(dimername);
    
    if(monomers.size()!=0) {
    	for(string s : monomers) {
    		mons.push_back(Monomer(s));
    	}
    }
    
    monomers
    

    bekommt seine Elemente und

    dimername
    

    seinen Wert von der Kommandozeile (Boost.program_options).

    Der Code laeuft so einwandfrei. Die nebenlaeufige Version:

            auto fd2=async(launch::async,[](string dimername) {
    		cout << this_thread::get_id() << endl;
    		Dimer dimer{dimername};
    		return dimer;
    	}, dimername);
    	
    	vector<Monomer> mons;
    	if(monomers.size()!=0) {
    		auto fd=async(launch::async,[](vector<string> monomers) {
    			cout << this_thread::get_id() << endl;
    			vector<Monomer> mons;
    			for(string s:monomers)
    				mons.push_back(Monomer(s));
    			return mons;
    		},monomers);
    		mons = fd.get();
    	}
           auto dimer = fd2.get();
    

    Beim Ausfuehren beendet das Programm mit einem seg-fault. Der gdb-backtrace lautet:

    #0  0x0000000000000000 in ?? ()
    #1  0x0000000000445fe3 in std::__future_base::_Task_setter<std::unique_ptr<std::__future_base::_Result<Dimer>, std::__future_base::_Result_base::_Deleter>, std::thread::_Invoker<std::tuple<main::{lambda(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)#1}, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, Dimer>::operator()() const [clone .isra.0] ()
    #2  0x0000000000446689 in std::_Function_handler<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> (), std::__future_base::_Task_setter<std::unique_ptr<std::__future_base::_Result<Dimer>, std::__future_base::_Result_base::_Deleter>, std::thread::_Invoker<std::tuple<main::{lambda(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)#1}, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, Dimer> >::_M_invoke(std::_Any_data const&) ()
    #3  0x000000000044749d in std::__future_base::_State_baseV2::_M_do_set(std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>*, bool*) ()
    #4  0x0000000000485c0f in __pthread_once_slow (once_control=0x6b9558, init_routine=0x4f55e0 <__once_proxy>) at pthread_once.c:116
    #5  0x0000000000445d4d in std::thread::_State_impl<std::thread::_Invoker<std::tuple<std::__future_base::_Async_state_impl<std::thread::_Invoker<std::tuple<main::{lambda(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)#1}, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, Dimer>::_Async_state_impl(std::tuple<main::{lambda(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)#1}, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >&&)::{lambda()#1}> > >::_M_run() ()
    #6  0x000000000050c9f4 in execute_native_thread_routine ()
    #7  0x0000000000482f49 in start_thread (arg=<optimized out>) at pthread_create.c:477
    #8  0x00000000005c22c3 in clone ()
    

    Leider habe ich keinen Dunst, wie man so einen backtrace analysiert oder interpretiert. Hat jemand eine Idee, was hier schief laeuft? Vielen Dank schonmal!


Log in to reply