Re: ReaderWriterLockSlim + Dispose?
- From: NvrBst <nvrbst@xxxxxxxxx>
- Date: Sat, 5 Apr 2008 11:17:01 -0700 (PDT)
On Apr 4, 10:28 pm, "Peter Duniho" <NpOeStPe...@xxxxxxxxxxxxxxxx>
wrote:
I can't say whether you're missing something. I do know that a quick
Google search yielded this link:http://blogs.msdn.com/vancem/archive/2006/03/29/564854.aspx
:) I did see that page before when searching "RWLS + dipose", it was
the only page that showed up on the first google results page that had
relavance. Aye, its not the ReaderWriterLockSlim class, but the
comments at the bottom did give me suspecions that cleaning up RWLS's
might not be needed that much.
In that particular example, you either need to decide whether you're going
to interrupt the threads that need the lock, or you're going to delay
cleanup of the lock until the threads are all done. You can't let the
threads run _and_ clean up the lock right away.
Aye. I understand this design wise, but, in the case of the thread
pool, you can't interrupt it. And waiting around for the threads to
finish isn't always a perferred solution; maybe the locks were there
to syncronize actions (IE in the case of a chat program, the thread
could lock the send/recive method on a line basis, so if you stop
locking the worst that could happen would be something like Msg1:
"hello jim." Msg2: "test", resulting in "hetleslo jim .\nt". If your
cleaning up, your probably not caring what else the threads going to
do as long as it doesn't crash, etc.
This example stores the instance in a static variable, so IDisposable
wouldn't apply.
Ahh. I always through using static on IDisposable objects was a no
no. But yes, I see now that if the IDisposable object is living to
the end of the application (which is the case of my RWLS's usally),
making them static would simplify my code a lot, and might be the
intended way of using them most the time. I'll look into this
approach more at the very least :)
Thanks for your comments, they were helpful. I usally use Monitor's
(+lock statments) anyway, but wanted to try a few applications with
RWLS and think static might be the way to go for some of the problems
I had with them.
NB
.
- Follow-Ups:
- Re: ReaderWriterLockSlim + Dispose?
- From: Peter Duniho
- 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
- ReaderWriterLockSlim + Dispose?
- Prev by Date: Re: redirection operator compatible console application
- Next by Date: Re: c# use an object instance across appdomains
- Previous by thread: Re: ReaderWriterLockSlim + Dispose?
- Next by thread: Re: ReaderWriterLockSlim + Dispose?
- Index(es):
Relevant Pages
|