On Feb 23, 10:54 am, "better_cs_...@yahoo.com"
<better_cs_...@yahoo.com> wrote:
Hello all,
I suspect that a threading issue is leading to an object being
destructed in one thread context while one of its member functions is
still running in another thread context. As a means of confirming
this, I would like to have the object check if it is alive in the
referenced member function and report to me if it is not. However, I
cannot think of a standards-compliant way for an object to know that
it has been destructed.
Can anybody confirm that this *cannot* be done? If it cannot, can
anybody suggest any alternatives?
Ignoring the threads aspect of this, the simplest way is to add a
private bool member and an isValid() member function:
[untested code]
class yourClass {
private:
bool valid_;
protected:
bool isValid() { return valid_; }
public:
yourClass() : valid_(true) {}
~yourClass() { valid_ = false; }
// Rest of yourClass
};
Now have each member function check isValid() before proceeding. For
debugging purposes, you might just add an assert(isValid()); to the
beginning of each member function.
Threads make this much more complicated of course - you would need
some sort of mutex or other device to ensure that the object wasn't
destructed while in the member function.
Best regards,
Tom
The above isn't "standards-compliant" as requested. If another object is