Hi,

I am so far familiar with the C# lock keyword, which I understand
prevents any other thread from entering the portion of code which is
locked, assuming you are locking the same object instance.

I have a cache of data which initially I locked when I write to it,
and I locked the same object for any reading.

But this will soon become a performance issue, as many threads need to
read it concurrently.

What is the optimal approach?

thanks!

Tim

Re: Threads, lock, many readers, one exclusive writer by Joe

Joe
Mon Dec 13 22:44:20 CST 2004

Hi Tim,

You could try a ReaderWriter lock to see if it improves performance in your
scenario:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemthreadingreaderwriterlockclasstopic.asp

Joe
--
http://www.csharp-station.com

"Tim Smith" <timasmith@hotmail.com> wrote in message
news:a7234bb1.0412132020.1848dc04@posting.google.com...
> Hi,
>
> I am so far familiar with the C# lock keyword, which I understand
> prevents any other thread from entering the portion of code which is
> locked, assuming you are locking the same object instance.
>
> I have a cache of data which initially I locked when I write to it,
> and I locked the same object for any reading.
>
> But this will soon become a performance issue, as many threads need to
> read it concurrently.
>
> What is the optimal approach?
>
> thanks!
>
> Tim