Re: Synchronized Collection<T> Recommendation
- From: "William Stacey [MVP]" <william.stacey@xxxxxxxxx>
- Date: Sun, 30 Apr 2006 14:47:18 -0400
| The answer is easy; by using lock you presume to know the usage profile of
| the consumer is one that doesn't favor a higher read frequency. By using
the
| ReaderWriterLock class, you favor either choice.
I think I said, don't assume anything. Let the consumer decide.
| > Is your collection doing anything besides updating a list?
| Again, by assuming an answer here you presume to know the usage profile of
| the consumer of the collection. In this case, you assume the to know the
| consumer favors reads equally as they favor writes. Regardless of whether
my
I was trying not assume, that is why I asked the question. What does your
collection do? As the answer can help dictate the lock to use.
ReaderWriter is not free. It is factors slower then a single monitor, so I
would just not use it everywhere as an alternative to monitor. Plus a RW,
can be unfair to writers (which may or may not be an issue for you). If
your readers are processing or blocking a long time, then a RW can be a good
thing. If not, on a single cpu it will not even help. On a multi-cpu it
may help a little. But if you are in and out of the read lock fast (i.e.
few non-blocking instructions) then the odds are there will not be
contention for the lock anyway and you only increase the odds of contention
using the slower lock (over a monitor). Naturally, testing perf is the only
way to know for sure.
--
William Stacey [MVP]
.
- Follow-Ups:
- 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
- Re: Synchronized Collection<T> Recommendation
- From: William Stacey [MVP]
- Re: Synchronized Collection<T> Recommendation
- From: Michael Primeaux
- Re: Synchronized Collection<T> Recommendation
- From: William Stacey [MVP]
- Re: Synchronized Collection<T> Recommendation
- From: Michael Primeaux
- Synchronized Collection<T> Recommendation
- Prev by Date: Re: Project fails to load after changing the name of the project folde
- Next by Date: Re: Synchronized Collection<T> Recommendation
- Previous by thread: Re: Synchronized Collection<T> Recommendation
- Next by thread: Re: Synchronized Collection<T> Recommendation
- Index(es):
Relevant Pages
|
|