Boost logo

Boost Users :

Subject: Re: [Boost-users] question about boost::thread
From: Mike Marchywka (marchywka_at_[hidden])
Date: 2008-09-15 11:59:44


________________________________
> Date: Mon, 15 Sep 2008 10:06:12 -0500
> From: lipingshan72_at_[hidden]
> To: boost-users_at_[hidden]
> Subject: Re: [Boost-users] question about boost::thread
>
> Thank you for the reply.
>
> This is just a testing program for this question. What you said is that even the destructor is called for ClassA, and TestClass is out off scope in main function, the memory for ClassA may still be around and valid on the main thread's stack. I think I have to agree with you that this is depended on the compiler. According to C++ standard, "the object no longer exists" once a destructor is invoked for an object. It depends on how do we understand this "no longer exists".

There is no garbage collector in the C++ runtime and hopefully a dtor does very little other
than tell everyone a piece of memory is available. Note of course that initialization
isn't guarnateed either. Popping things from a stack should look like sp+=n , not clearing
each defunct element. I wouldn't expect a heap to be returned to the OS on every
delete either.

>
> From the C++ standard : (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2723.pdf)
> Once a destructor is invoked for an object, the object no longer exists; the behavior is undefined if the destructor is invoked for an object whose lifetime has ended.
>
> On Fri, Sep 12, 2008 at 5:36 PM, Steven Watanabe <watanabesj_at_[hidden]> wrote:
> AMDG
>
>
> PingShan Li wrote:
> Here is my test program using boost::thread. I would expect this program to
> crash inside FunctionA because m_ClassA is no longer available.
>
> Can anybody help me to understand why it does not crash? thank you.
>
>
> Incorrect programs are not guaranteed to crash.
> The memory for m_ClassA is on the main thread's
> stack and is almost certain to still be valid (at the
> machine level) when FunctionA is called. In fact,
> depending on your compiler it may not have been
> overwritten at all.
>
> In Christ,
> Steven Watanabe
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users

_________________________________________________________________
Stay up to date on your PC, the Web, and your mobile phone with Windows Live.
http://clk.atdmt.com/MRT/go/msnnkwxp1020093185mrt/direct/01/


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