Re: Synchronized Collection<T> Recommendation
- From: "Michael Primeaux" <mjprimeaux@xxxxxxx>
- Date: Sun, 30 Apr 2006 11:27:35 -0500
Hit SEND too soon.
That is true if I were to use lock / Monitor. I prefer to use the
ReaderWriterLock class in more cases (especially for the SyncRoot property)
for obvious reasons; I can't know (or presume to know) the usage profile of
the consumer.
The purpose of the SyncRoot property IS to leaverage the lock for other
scenarios outside of the collection but as related TO the collection.
I'll still keep my opinion; but then again, you know what those are like ;-)
"William Stacey [MVP]" <william.stacey@xxxxxxxxx> wrote in message
news:%23BbdJIHbGHA.4972@xxxxxxxxxxxxxxxxxxxxxxx
| IMHO, I disagree with Microsoft's reasoning:
| http://blogs.msdn.com/brada/archive/2003/09/28/50391.aspx and do
certainly
| find use for the SyncRoot and IsSynchronized properties in
multi-operation
| scenarios (i.e. add one item and remove another in the same protected
| operation).
I have to agree with MS on this one. To add an item and remove in the
same
protected operation means your taking the lock 3 times. Once for the
lock(SyncRoot), and once for each method internally. If you add a .Count
in
there, then its four locks. True, you already own the lock, so the other
lock operations are faster, but it is still wasted overhead. As a user of
the collection, it often cleaner, and faster, to just use your own lock
and
sync access to the collection yourself. Plus you may need to leverage
that
lock for other issues outside of the collection.
--
William Stacey [MVP]
.
- Follow-Ups:
- Re: Synchronized Collection<T> Recommendation
- From: William Stacey [MVP]
- Re: Synchronized Collection<T> Recommendation
- References:
- Synchronized Collection<T> Recommendation
- From: Michael Primeaux
- Re: Synchronized Collection<T> Recommendation
- From: Chris Chilvers
- Re: Synchronized Collection<T> Recommendation
- From: Michael Primeaux
- Re: Synchronized Collection<T> Recommendation
- From: William Stacey [MVP]
- Synchronized Collection<T> Recommendation
- Prev by Date: Re: Synchronized Collection<T> Recommendation
- Next by Date: Re: When, why and where should a struct be used?
- Previous by thread: Re: Synchronized Collection<T> Recommendation
- Next by thread: Re: Synchronized Collection<T> Recommendation
- Index(es):
Relevant Pages
|
Loading