Re: Synchronized Collection<T> Recommendation
- From: "William Stacey [MVP]" <william.stacey@xxxxxxxxx>
- Date: Sun, 30 Apr 2006 12:20:43 -0400
| 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: Michael Primeaux
- Re: Synchronized Collection<T> Recommendation
- From: Michael Primeaux
- 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
- Synchronized Collection<T> Recommendation
- Prev by Date: Re: why float
- Next by Date: Re: uint64
- Previous by thread: Re: Synchronized Collection<T> Recommendation
- Next by thread: Re: Synchronized Collection<T> Recommendation
- Index(es):
Relevant Pages
|
Loading