Bad access in boost :: future <>. Then () after accessing this future

I am developing for iOS in Xcode 4.6. I am writing a library for a service and use boost to start threads. One of my methods is as follows:

void Service::start(boost::shared_ptr<ResultListener> listener) {

    boost::future<bool> con = boost::make_future(true);
    listener->onConnected(); // Works
    boost::future<bool> initDone = con.then([&, listener](boost::future<bool>& connected) {
         listener->onConnected(); // Works
         if (!connected.get()) {
             listener->onError("...");
             return false;
         }
         listener->onError("...");  // EXC_BAD_ACCESS
         /* ... */
         return true;
    });
}

When doing this on the device, I get EXC_BAD_ACCESSon the marked line. I am very surprised by this, since the first call onConnectedis successful, and even if I add the onErrorcall before if, it also works.

++, , , , , . , . , , , , : ResultListener Service - boost::noncopyable. shared_ptr ( use_count) . boost 1.53.

Servuce reco(/* ... */);
boost::shared_ptr<foo> f(new foo());
reco.start(f);

foo , , std::cout, .

: get(), future.hpp:

    // retrieving the value
    move_dest_type get()
    {
        if(!this->future_)
        {
            boost::throw_exception(future_uninitialized());
        }

        future_ptr fut_=this->future_;
        this->future_.reset();
        return fut_->get();
    }

, . reset(), -, future_ shared_ptr. , , , , , listener, . ? - ?

2: :

#define BOOST_THREAD_VERSION 4
#include <boost/thread.hpp>

class Test {

public:
    void test() {
        boost::shared_ptr<Test> listener(new Test());
        boost::future<bool> con = boost::make_future(true);
        listener->foo(); // Works
        boost::future<bool> initDone = con.then([listener](boost::future<bool>& connected) {
            listener->foo(); // Works
            if (!connected.get()) {
                listener->foo();
                return false;
            }
            listener->foo();  // EXC_BAD_ACCESS
            return true;
        });
    }

    void foo() {
        std::cout << "foo";
    }
};

, XCode, , , , Mankarnas ( ) () : , , , undefined.

, get(): Situation before <code> get </code> is called

get(): Situation after <code> get </code> was called

px 0x00.

+5
1

1.53 . , future.then , , .

#define BOOST_THREAD_DONT_PROVIDE_FUTURE_INVALID_AFTER_GET

, ( ).

, .

+2

All Articles