Re: Why could a suspended thread leak?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



hi Pete

On Feb 3, 4:03 am, "Peter Duniho" <NpOeStPe...@xxxxxxxxxxxxxxxx>
wrote:
On Mon, 02 Feb 2009 14:12:49 -0800, <beginwi...@xxxxxxxxx> wrote:
[...]
"Or if you're maintaining state in some sort of data structure
that is reachable even without the thread executing, a similar thing
could
happen. "

* So with “is reachable even without the thread executing” you were
referring to objects  “local” ( thus no other thread references them )
to the aborted/suspended thread, which  ( even though there are no
longer any references to them ) are still somehow reachable?

No, I'm referring to objects reachable via some other data structure.

It would be useful for you to not mix "aborted" and "suspended".  Those  
are two very different scenarios, and you can't really apply the same  
reasoning to each.

For aborted threads, the stack goes away.  Local variables no longer  
exist, so the only way an object referenced by the thread could still be  
reachable is if there's a reference somewhere else.  Such in a static  
variable, or some data structure that is itself referenced (directly or  
indirectly) by a static variable.


So if thread T1 wasn’t aborted, then T1 would be able to somehow
manage to make the object to become unreachable ( when not wanted
anymore )?
But if thread is aborted, then that may not happen and thus object is
still reachable ( app still references it via some static variable
or… ) even when not needed/wanted anymore? And that is considered a
leak


For suspended threads, the stack remains.  Objects remain reachable simply  > by virtue of being referenced even simply within the stack as local  
variables.  If a thread had a reference to an object before it's  
suspended, it continues to have a reference to the object after it's  
suspended.


And why would that be considered a problem ( why would we call it
leaking )? Thread will simply “make” object unreachable when it is
resumed?!




The reason you don't know the state of the thread when using Abort() or
Suspend() is that there's nothing that would let your code know what
instruction the thread being aborted or suspended is executing.  Keeping
in mind also that the thread executes instructions, not statements, so  
you
could even wind up aborting or suspending a thread mid-statement.

* But if thread only gets aborted/suspended when it executes Abort/
Suspend statement,

False predicate results in a trivially true "if/then" statement.

In other words, it's simply not true that a "thread only get  
aborted/suspended when it executes Abort()/Suspend() statement".  In fact,  
the only interesting uses of those methods is when they are called by a  
thread other than the one being aborted or suspended.

And hopefully with that, you understand why using those methods can result  
in unpredictable results.

yep :)



thank you
.



Relevant Pages

  • Re: Zero Rreferences (was:Stupid Question)
    ... > method to ensuring that there are no references left? ... IF one does not need a complex data Structure, ... Primates DO IT! ...
    (perl.beginners)
  • Re: Process to modify multiple queries simultaneously
    ... hundreds of combo box references already in my end user form I simply added ... that references that Combo box. ... you lost me on data structure. ... "Jeff Boyce" wrote: ...
    (microsoft.public.access.queries)
  • Re: 2.6.21-rc1: known regressions (part 2)
    ... Subject: ThinkPad T60: system doesn't come out of suspend to RAM ... References: http://lkml.org/lkml/2007/2/22/391 ... Status: unknown ...
    (Linux-Kernel)
  • Re: copying hashes without references
    ... > to parse). ... I created a hash with the common attributes and tried to ... If you want to really copy the contents of a data structure ... instead of the references it contains, this is called a "deep copy". ...
    (comp.lang.perl.misc)
  • [4/6] 2.6.21-rc3: known regressions
    ... If you find your name in the Cc header, you are either submitter of one ... ThinkPad doesn't resume from suspend to RAM ... References: http://lkml.org/lkml/2007/2/27/80 ... Patch: http://lkml.org/lkml/2007/3/12/228 ...
    (Linux-Kernel)