From the course: Threading in C#

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Reader/writer lock

Reader/writer lock - C# Tutorial

From the course: Threading in C#

Start my 1-month free trial

Reader/writer lock

- [Instructor] There are times when we need to work with a resource like a file that would be updated very rarely but could be read quite a few different times with different threads. So that's where we use read or writer locks. So we can start with simulating a read function and use a for loop that runs from zero to 10 and this is where we would like to use a read lock on a particular resource and then let it sleep for some time and then exit the read lock. So for that we need to clear the read lock, we can say static, reader, writer lock and there's a slim version. If you're using semi for slim, that means it performs better than semi for. And if you're using reader writer lock slim, that means it performed better than the actual reader writer that comes with dot net. We can call it reader writer lock slim and instantiate it right here so we have to do this only one time. Now an actual resource instead of using a file or something I like to just create a static dictionary which has…

Contents