Re: Dispose must be thread-safe ?
From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 02/27/04
- Next message: Valery Pryamikov: "Re: Dispose must be thread-safe ?"
- Previous message: Ales Pour: "Re: Dispose must be thread-safe ?"
- In reply to: Ales Pour: "Re: Dispose must be thread-safe ?"
- Next in thread: Valery Pryamikov: "Re: Dispose must be thread-safe ?"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 27 Feb 2004 10:46:52 -0000
Ales Pour <ales.pour@systinet.com> wrote:
> "Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in message
> > > 1.. Two threads are calling Dispose of the same object concurrently;
> >
> > Well yes - but that's surely a truism. However, one of those threads
> > *can* be the finalizer thread. If you intended that to be read as "Two
>
> I admit that due to my limited knowledge of GC-ing in .NET I was not able to
> track the whole discussion, but I dare to wonder - how come that one of
> threads can be the finalizer thread, while the object is still in use (since
> other thread still references it and even calls Dispose method on it)??
The other thread effectively doesn't need the reference any more - it's
(provably) not accessing any members any more. Basically, a lot of
people (me included) always assumed that any stack frame in an instance
method would include an implicit "root" (from the garbage collector's
point of view) to "this" - but it's *not* always a root, if it's not
needed.
Effectively, you could think of each method as having a local variable
called "this" which is passed to it. When that variable is no longer
being used, it doesn't stop the garbage collector from trying to
collect the object.
-- Jon Skeet - <skeet@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
- Next message: Valery Pryamikov: "Re: Dispose must be thread-safe ?"
- Previous message: Ales Pour: "Re: Dispose must be thread-safe ?"
- In reply to: Ales Pour: "Re: Dispose must be thread-safe ?"
- Next in thread: Valery Pryamikov: "Re: Dispose must be thread-safe ?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|