Just take a lock (read or write, depending) on the Dictionary<X,Y> object
(the actual object, not the type) before you call its methods and you should
be fine.

If you run into performance issues, then you can look at more granular
locking or another strategy, but locking the object before any use is
definitely the easiest/safest way to go.

On 4/5/06, James Berry <[EMAIL PROTECTED]> wrote:
>
> I think I probably do require reads to be blocked during a write - but
> specifically, I don't know how Dictionary<X,Y> works so I wasn't clear
> on how much locking I should be doing.
>
> Best wishes
> James
>
>
> -----Original Message-----
> From: Discussion of advanced .NET topics.
> [mailto:[EMAIL PROTECTED] On Behalf Of Peter Ritchie
> Sent: 05 April 2006 18:50
> To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM
> Subject: Re: [ADVANCED-DOTNET] Dictionary multi-reader single writer
>
> I, too, assumed James would require reads to be blocked during a write;
> making ReaderWriterLock an excellent candidate.
>
> Vance Morrison has a good blog entry on ReaderWriterLock (which also
> references some of his excellent articles on multi-threading) that
> discusses the performance of ReaderWriterLock in .NET 2.0 (and, I'll
> assume, 1.x) [1]
>
> [1] http://blogs.msdn.com/vancem/archive/2006/03/28/563180.aspx
>
> -- Peter
> _____
> http://www.peterRitchie.com/Blog/DotNetConfig.xsd
>
> On Wed, 5 Apr 2006 12:17:25 -0500, Eric Means <[EMAIL PROTECTED]>
> wrote:
>
> >ReaderWriterLock?
> >
> >On 4/5/06, James Berry <[EMAIL PROTECTED]> wrote:
> >>
> >> Hi
> >>
> >> I have a Dictionary<X,Y>
> >>
> >> I want to look up X's in my dictionary a lot from multiple threads.
> >> I want to add items to my dictionary occasionally from some of these
> >> threads.  I would like the reads to proceed concurrently without
> >> locking, but I am not sure of the right pattern - can anyone help?
>
> ===================================
> This list is hosted by DevelopMentor(r)  http://www.develop.com
>
> View archives and manage your subscription(s) at
> http://discuss.develop.com
>
> ===================================
> This list is hosted by DevelopMentor(r)  http://www.develop.com
>
> View archives and manage your subscription(s) at
> http://discuss.develop.com
>



--
Eric Means
[EMAIL PROTECTED]
http://www.randomtree.org/eric/

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to