Re: ReaderWriterLockSlim + Dispose?
- From: NvrBst <nvrbst@xxxxxxxxx>
- Date: Sun, 6 Apr 2008 17:54:31 -0700 (PDT)
I only thought you said that because you did. I'm happy if you want to
retract the previous example, but you did post that scenario as an example.
That was an example to illustrate what would happen if you got past
the (disposable) lock before it disposed, but not result in a crash
and be a valid "not care about the results anymore"; user wise. If it
was before the lock when it disposed, then it wouldn't result in any
output because it'd see the object is disposed and just skip to the
end. It's like using it to generlize the topic to chat programs only
- "whats all this talk about thread pools, I thought we were talking
about chat programs"
Again: I never once suggested that you _should_ be aborting thread pool
Amusing, red herring? You gave the example. Said its the only valid
way if you were in that situation to safly clean up (which I
dissagreeded with). You can keep following the straw man argument
above if you like, but don't tell me to not try to refret the "only"
way to safly dispose the thread pool without waiting argument you
gave, and then call it a red herring.
However, Microsoft does also specifically _recommend_ that
if you implement Dispose() that it be valid to call Dispose() multiple
times safely.
I didn't design the dispose pattern. It comes with a "disposed" flag
that they expect you to use. What if 2 objects try to dispose at the
same time, and both objects try setting the "disposed" flag to false
at the same time? Is the design patter flawed? Not really, the
situation doesn't really occur ever, but it probably can since who
knows when the GC will call it. I wouldn't spend too much time trying
to fix this situation even though it can potentially exsist.
"Most likely never happen" is NEVER an appropriate design
philosophy.
I'm not too sure about this statment... It's not that perfect of a
world.
It's no more off-topic than any other programming design thread
:) It's definally off-topic, but I retract my previous statment. It's
not pathedic, I don't know why I said that. I don't see myself as the
kind of person who has a problem admiting I made a mistake, I just
don't agree with your view.
In my opinion, it's possible to (as reliably as other programs), clean
up an object and not be forced to wait for the threads inside it to
finish, or force threads to stop with an abort. Mainly in the case
where you don't care about the result of the threads anymore. Another
example could be that you send 100 threads off to get an answer, you
got the answer when the 3rd thread returned. You can do clean up and
ignore the other threads as long as you have dispose checks (or try
catch statments (or both)), around the objects you clean up.
Now don't get me wrong. A disposable sychronization lock did seem
very strange to me (point of the topic), and obviously makes using
this type of lock in a situation where you want to do fast clean up
makes it harder (if statmtnet, or try catch statments, everytime you
try and aquire a lock). But this isn't a bad design, the benifites
can be good.
IE in the previous example changing all the "if(!disposed)
myStringLock.EnterWriteLock(); else return;" to "try
{ myStringLock.EnterWriteLock(); } catch { return; }" would fix any
possible crashes, and be a concret example with no possible chance of
crashing, yet have everything synched.
:) NB
.
- Follow-Ups:
- Re: ReaderWriterLockSlim + Dispose?
- From: Peter Duniho
- Re: ReaderWriterLockSlim + Dispose?
- From: NvrBst
- Re: ReaderWriterLockSlim + Dispose?
- References:
- ReaderWriterLockSlim + Dispose?
- From: NvrBst
- Re: ReaderWriterLockSlim + Dispose?
- From: Peter Duniho
- Re: ReaderWriterLockSlim + Dispose?
- From: NvrBst
- Re: ReaderWriterLockSlim + Dispose?
- From: Peter Duniho
- Re: ReaderWriterLockSlim + Dispose?
- From: NvrBst
- Re: ReaderWriterLockSlim + Dispose?
- From: Peter Duniho
- Re: ReaderWriterLockSlim + Dispose?
- From: NvrBst
- Re: ReaderWriterLockSlim + Dispose?
- From: Peter Duniho
- Re: ReaderWriterLockSlim + Dispose?
- From: NvrBst
- Re: ReaderWriterLockSlim + Dispose?
- From: Peter Duniho
- Re: ReaderWriterLockSlim + Dispose?
- From: NvrBst
- Re: ReaderWriterLockSlim + Dispose?
- From: Peter Duniho
- Re: ReaderWriterLockSlim + Dispose?
- From: NvrBst
- Re: ReaderWriterLockSlim + Dispose?
- From: Peter Duniho
- ReaderWriterLockSlim + Dispose?
- Prev by Date: Re: ReaderWriterLockSlim + Dispose?
- Next by Date: Re: ReaderWriterLockSlim + Dispose?
- Previous by thread: Re: ReaderWriterLockSlim + Dispose?
- Next by thread: Re: ReaderWriterLockSlim + Dispose?
- Index(es):
Relevant Pages
|
Loading