Boost logo

Boost Users :

Subject: Re: [Boost-users] [asio] What happens when a deadline_timer is deleted
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-09-01 10:50:03


AMDG

Bjarne Laursen wrote:
> If I have a deadline_timer in my class and my class is deleted, the
> compleetion function will be called (with error code). But as the
> destructor have already been run I guess that the 'this' pointer will
> be invalid!

Correct.

> Is this safe?

No.

> What if my compleetion function is virtual?

It doesn't matter.

> timer.async_wait(boost::bind(&MyClass::OnTimer, this,
> boost::asio::placeholders::error));

The safest way to handle it is to use shared_ptr and
enable_shared_from_this.

In Christ,
Steven Watanabe


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