Re: Synchronized Collection<T> Recommendation



| 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]



.



Relevant Pages

  • Re: Question about vZOOM reference handling
    ... consumer message queues which go to two different consumer threads. ... But vZOOM still can be used here for readers. ... to just use a lock on the writer side. ...
    (comp.programming.threads)
  • System.Threading.Monitor question
    ... Exploring the C# lock, I wrote the simple multi-threaded IEnumerator ... consumer, below. ... private ArrayList member of the same object as threadProc. ...
    (microsoft.public.dotnet.framework)
  • Re: Scottrades pain in the butt download
    ... but it's still frustrating and amazing how EVERY software ... company just blatantly rips off the consumer by attempting ... to lock us into ever-more unreliable and unusable bloatware... ... ripping of the individual consumer is precisely the ...
    (misc.invest.stocks)
  • Re: System.Threading.Monitor question
    ... necessarily means that another thread already has a lock. ... how can a thread be blocked waiting if there is no lock? ... > consumer, below. ... > private ArrayList member of the same object as threadProc. ...
    (microsoft.public.dotnet.framework)
  • Re: Efficient hashmap serialization?
    ... Once RMI gets it's mits on the Hashtable I presume it keeps the lock ... exclusively so for the transmission I don't think that would be a ...
    (comp.lang.java.programmer)