Are you implying
that the ReaderWriterLockSlim.Dispose() is less important than for other
classes that implement IDisposable?
Hehe, aye, that was my question. For example, if it was a file, and
others are potentially wanting to use the file, then I'd rank high on
"definally dispose when your done". But I've never really worked with
these "WaitHandles". Are they low priority to close? Does the OS
just create new ones when people request them, so it doesn't matter
even a little bit if the one ReaderWriterLockSlim is using isn't
closed for a few mins after its done with it? I only see a memory
potential problem here, but its not like WaitHandles are images, no
one really cares about a few bytes till GC collects it (unless its in
some kind of loop). Again, I could be wrong, which is why I'm asking,
basically what I'm missing.
Do you mean that the examples use ReaderWriterLockSlim but don't dispose
it when the code is done with it? That's a bug.
http://msdn2.microsoft.com/en-us/library/system.threading.readerwriterlockslim.aspx
http://msdn2.microsoft.com/en-us/library/bb355025.aspx
http://www.bluebytesoftware.com/blog/PermaLink,guid,c4ea3d6d-190a-48f8-a677-44a438d8386b.aspx
To name a few. The 1st MSDN example displays the entire class with no
dispose in it. If you google / google code search
"ReaderWriterLockSlim" I don't think you'll be able to find a code
snipplet or example that uses dispose with RWLS, which I found very
strange. This made me believe that there is something I'm missing?
Possible responsing I might of been expecting after posting was stuff
like:
"Ahh, its because all those examples are used in the main object,
where 99.9% of locks are used. Since the application closes when your
done with the object, that uses the RWLS, no one worries about using
the dispose method for RWLS. Its just correctness for the other 0.1%
of the time someone might be using it in a class that gets created
thousands of times, and thus may want to clean it up after its done.".
Or maybe a "Its a new class so people havn't learned how to use it
correctly yet, I'd highly suggest always calling the Dispose, even if
its in your main object; YOU DEFINALLY DON'T WANT THOSE WAITHANDLES
FLOATING AROUND ANYLONGER THAN YOU HAVE TOO".
Basically, for example, every code snipplet/example on say
StreamReader has the Dispose method with it, why doesn't
ReaderWriterLockSlim?
I don't understand why it's a problem. Why do you have to check to see if
the lock is disposed? Why would it be disposed unless you're sure you're
done with it (i.e. your own Dispose() method has been called)?
There are reasions. For example, if your sychronizing a thread pool
with RWLS's, then you can't do something like "stop all theads, its
time to clean up" that I know of. A real life example could be, say
your making a macroing program. Its designed to run multiple macros
at the same time and are using the thread pool. Even if you know 5
macros are running (maybe in constant loops), it's time to clean up or
shut down, you don't know how long they are going to take. Since the
client made the macro(script) it could be doing some kind of huge loop
and don't want to wait for it. Cleaning up could result in that
thread trying to use the lock, which is annoying in the case of RWLS-
if its the only disposable thing in the application. With the thread
pool, any situation you don't want to wait for the threads to finish
before cleaning up could result in crashes if you don't check if the
lock is disposed before acquiring it.
Yes yes, you probably don't want to use the thread pool in that type
of situation, but not knowing when the threads are going to be done is
somewhat common, even if you did know you don't always want to wait
around for it to finish (expecially in the case of a thread pool where
you can't interrupt/abort it, and who knows how long till it checks
for a stop variable).
Not necessarily. If the finalizer thread gets around to running, they
will eventually get cleaned up, yes. But there's no guarantee that this
will ever happen, or when it will happen. You should not design code that
relies on that (other than implementing your own finalizer, of course).
Which was another question. Does it really matter if these
"WaitHandles" don't get cleaned up for a while? How does it affect
other things if at all? (Other than maybe some memory that lingering
till GC Collects / AppDomain unloads?). I don't see these WaitHandles
being very big though memory wize though.
[...] If you don't need the added functionality that ReaderWriterLockSlim
provides, then you might as well use one of the simpler, non-disposable
synchronization techniques. Alternatively, you could use the older
ReaderWriterLock class, and accept the additional performance overhead it
has.
I was thinking maybe the other implementations use WaitHandles and
just don't clean them up? How many ways can there be for locks to
wait on an event

Hehe, my last posts last paragraph was more so
asking this question. IE Maybe RWSL, without disposing, is very close
to how Monitor works. It might not be but I was also fishing for any
type of information with locks with the statment

Thanks for the comments, I'm still a little curious on information
though about the topic.