Boost logo

Boost Users :

Subject: [Boost-users] boost::bind - What if bound (method, instance) doesn't exist anymore?
From: Christopher Pisz (cpisz_at_[hidden])
Date: 2011-10-06 11:41:00


I've got some problem with the shared_ptr usage in my library.
I am suspecting its in combination with boost::bind.

What happens when a boost::function is called and has been created with a
(method, instance) combination, but the instance no longer exists?

What happens when this is in combination with boost::asio::io_service?

Here is my suspect code:

B::SharedPtr me = boost::dynamic_pointer_cast<B, A>(shared_from_this());
callback = boost::bind(&B::Foo, me, boost::asio::placeholder::error);

// this is a boost::asio::ip::tcp::acceptor
acceptor.async_accept(socket_, callback);

Now suppose I use a raw pointer instead.
Now suppose the instance that just got bound was destroyed before the accept
happened.

What will be the result?

I'd try to just type up a test myself, but this requires alot of foundation
code.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net