<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Low-Lock Techniques in action: Implementing a Reader-Writer lock</title><link>http://blogs.msdn.com/vancem/archive/2006/03/28/563180.aspx</link><description>In my article What Every Dev Must Know About Multithreaded Apps I discuss the fundamental principles of using locks correctly. In that article I strongly encourage the use of reader-writer locks because these locks create the protection you need (insuring</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Low-Lock Techniques in action: Implementing a Reader-Writer lock</title><link>http://blogs.msdn.com/vancem/archive/2006/03/28/563180.aspx#563213</link><pubDate>Tue, 28 Mar 2006 20:21:16 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:563213</guid><dc:creator>Peter Ritchie</dc:creator><description>Vance, in your ReaderWriterLock sample use, is your comment &amp;quot;// No readers or other writers can be in here.&amp;quot; suggestiong that another &amp;nbsp;myLock.AcquireWriterLock(...) call would block?</description></item><item><title>re: Low-Lock Techniques in action: Implementing a Reader-Writer lock</title><link>http://blogs.msdn.com/vancem/archive/2006/03/28/563180.aspx#563239</link><pubDate>Tue, 28 Mar 2006 20:47:05 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:563239</guid><dc:creator>Peter Ritchie</dc:creator><description>Vance, are you suggesting by the comment &amp;quot;// No readers or other writers can be in here.&amp;quot; in the ReaderWriterLock sample use that adding another call to myLock.AcquireWriterLock(...) before myLock.ReleaseWriterLock() would block or throw an exception?</description></item><item><title>re: Low-Lock Techniques in action: Implementing a Reader-Writer lock</title><link>http://blogs.msdn.com/vancem/archive/2006/03/28/563180.aspx#563295</link><pubDate>Tue, 28 Mar 2006 21:30:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:563295</guid><dc:creator>vancem</dc:creator><description>Peter:&lt;br&gt;&lt;br&gt;The // No readers or other writers can be in here comment does mean you indicate, that a call to myLock.AquireWriterLock or myLock.AquireReaderLock will block (wait), until the lock is released. &amp;nbsp;&lt;br&gt;</description></item><item><title>re: Low-Lock Techniques in action: Implementing a Reader-Writer lock</title><link>http://blogs.msdn.com/vancem/archive/2006/03/28/563180.aspx#563315</link><pubDate>Tue, 28 Mar 2006 21:55:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:563315</guid><dc:creator>Peter Ritchie</dc:creator><description>Vance, the documentation for ReaderWriterLock.AcquireWriterLock states: &amp;quot;AcquireWriterLock supports recursive writer-lock requests. That is, a thread can call AcquireWriterLock multiple times, which increments the lock count each time. ... Recursive lock requests are always granted immediately, without placing the requesting thread in the writer queue.&amp;quot; &amp;nbsp;So, adding another myLockAcquireWriter(...) before myLock.ReleaseWriterLock() will never block. &amp;nbsp;Your new comment should say AcquireReaderLock() blocks not Acquire*Lock() blocks.&lt;br&gt;&lt;br&gt;Of course, that presupposes a matching ReleaseWriterLock() is added to any additional AcquireWriterLock()...</description></item><item><title>re: Low-Lock Techniques in action: Implementing a Reader-Writer lock</title><link>http://blogs.msdn.com/vancem/archive/2006/03/28/563180.aspx#563319</link><pubDate>Tue, 28 Mar 2006 21:59:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:563319</guid><dc:creator>Peter Ritchie</dc:creator><description>A quick test of:&lt;br&gt;&lt;br&gt;MyReaderWriterLock myLock = new MyReaderWriterLock();&lt;br&gt;&lt;br&gt;myLock.AcquireWriterLock(Timeout.Infinite);&lt;br&gt;myLock.AcquireWriterLock(Timeout.Infinite);&lt;br&gt;myLock.ReleaseWriterLock();&lt;br&gt;myLock.ReleaseWriterLock();&lt;br&gt;&lt;br&gt;confirms this.</description></item><item><title>re: Low-Lock Techniques in action: Implementing a Reader-Writer lock</title><link>http://blogs.msdn.com/vancem/archive/2006/03/28/563180.aspx#563402</link><pubDate>Tue, 28 Mar 2006 23:48:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:563402</guid><dc:creator>vancem</dc:creator><description>Peter:&lt;br&gt;&lt;br&gt;Yes, you are correct that the current implementation of MyReaderWriterLock is NOT recurisve (reentrant). &amp;nbsp;This was last of the additions that I suggested was straightfoward to add. &amp;nbsp;You are correct that it is not a truely &amp;nbsp;drop-in replacement without it (but it is also not a drop-in replacement unless I implement all the other little-used APIs like lock upgrade). &amp;nbsp; &amp;nbsp;&lt;br&gt;&lt;br&gt;If you are interesting in seeing the reentrant version, I just say so and I can blog about that next.&lt;br&gt; &amp;nbsp;</description></item><item><title>re: Low-Lock Techniques in action: Implementing a Reader-Writer lock</title><link>http://blogs.msdn.com/vancem/archive/2006/03/28/563180.aspx#563430</link><pubDate>Wed, 29 Mar 2006 00:16:48 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:563430</guid><dc:creator>Peter Ritchie</dc:creator><description>Sorry, my code sample should have used ReaderWriterLock, not MyReaderWriterLock.</description></item><item><title>re: Low-Lock Techniques in action: Implementing a Reader-Writer lock</title><link>http://blogs.msdn.com/vancem/archive/2006/03/28/563180.aspx#563591</link><pubDate>Wed, 29 Mar 2006 04:51:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:563591</guid><dc:creator>snaveen</dc:creator><description>Other problems with ReaderWriterLock is that the reads have higher priority than the writes which I think shouldn’t. If there are few readers locking an object and a writer wants to write then writer should be given higher priority which I think is not that is happening in BCL ReadWriterLock due to this there is a starvation. This is one of the reason few of them aren’t using readerwriter lock other than the performance issue that you have mentioned.&lt;br&gt; &lt;br&gt;</description></item><item><title>re: Low-Lock Techniques in action: Implementing a Reader-Writer lock</title><link>http://blogs.msdn.com/vancem/archive/2006/03/28/563180.aspx#563650</link><pubDate>Wed, 29 Mar 2006 06:50:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:563650</guid><dc:creator>onovotny</dc:creator><description>It would be very nice if the reader writer lock could be finished up to be a nearly-complete replacement for the built-in version. &amp;nbsp;Perhaps it can live on a GotDotNet workspace?&lt;br&gt;&lt;br&gt;Thanks!&lt;br&gt;--Oren</description></item><item><title>re: Low-Lock Techniques in action: Implementing a Reader-Writer lock</title><link>http://blogs.msdn.com/vancem/archive/2006/03/28/563180.aspx#563796</link><pubDate>Wed, 29 Mar 2006 12:13:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:563796</guid><dc:creator>zahical</dc:creator><description>Thanks for the very interesting post. There aren’t many sources on the net about low-lock techniques, so anything about them is welcome.&lt;br&gt;Please, write more about it – though using low-lock techniques is not something that one happens to do everyday, for me, they are a very good way to learn some funny and obscure facts about the processor, the compiler and the .NET platform.&lt;br&gt;For me, personally, it will be very interesting (and educating) to see all the versions of the ReaderWriterLock that you mentioned – the one that is reentrant and the one that is fair about the waiters – alongside your comments what differences (behavioral and performance) &amp;nbsp;the changes in the implementation bring.&lt;br&gt;</description></item><item><title>Interesting Finds</title><link>http://blogs.msdn.com/vancem/archive/2006/03/28/563180.aspx#563828</link><pubDate>Wed, 29 Mar 2006 13:14:21 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:563828</guid><dc:creator>Jason Haley</dc:creator><description /></item><item><title>re: Low-Lock Techniques in action: Implementing a Reader-Writer lock</title><link>http://blogs.msdn.com/vancem/archive/2006/03/28/563180.aspx#564091</link><pubDate>Wed, 29 Mar 2006 19:59:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:564091</guid><dc:creator>vancem</dc:creator><description>In reply to snaveen's comment.&lt;br&gt;&lt;br&gt;In my experimentation I have personally confirmed that both System.Threading.ReaderWriterLock as well as the MyReaderWriteLock implementation will NOT starve writers. &amp;nbsp;If a writer is waiting for the lock, readers start to block also (They are logically 'behind' the writer in the queue), an so the writer gets the lock as soon as it can (when all the readers that currently hold the lock drain). &amp;nbsp;&lt;br&gt;&lt;br&gt;I am interested in any reasons why people don't use System.ThreadingReaderWriterLock. &amp;nbsp; Performance may be one of them (however, for other reasons it good to work in big enough chunks that lock performance is not an issue). &amp;nbsp; &lt;br&gt;</description></item><item><title>Analysis of Reader-Writer lock </title><link>http://blogs.msdn.com/vancem/archive/2006/03/28/563180.aspx#564855</link><pubDate>Thu, 30 Mar 2006 17:40:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:564855</guid><dc:creator>Vance Morrison's Weblog</dc:creator><description>In my last post I posted readerWriterDemo.cs&amp;amp;amp;nbsp;which is an implementation of a Reader-Writer lock.&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;...</description></item><item><title>Vance on reader-writer locks</title><link>http://blogs.msdn.com/vancem/archive/2006/03/28/563180.aspx#565147</link><pubDate>Thu, 30 Mar 2006 22:08:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:565147</guid><dc:creator>Generalities &amp; Details: Adventures in the High-tech Underbelly</dc:creator><description /></item><item><title>Using ReaderWriterLocks part 3 (last in this set)</title><link>http://blogs.msdn.com/vancem/archive/2006/03/28/563180.aspx#598469</link><pubDate>Tue, 16 May 2006 03:33:01 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:598469</guid><dc:creator>Rico Mariani's Performance Tidbits</dc:creator><description>Well I think it's raining ReaderWriterLocks this month!&amp;amp;amp;nbsp; Jeff Richter has an article on MSDN that...</description></item><item><title>Locking code</title><link>http://blogs.msdn.com/vancem/archive/2006/03/28/563180.aspx#8996149</link><pubDate>Sat, 11 Oct 2008 20:16:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8996149</guid><dc:creator>IWebThereforeIAm</dc:creator><description>&lt;p&gt;Locking code Monitor.TryEnter, lock, using, and Deadlock Jeffrey Richter has an article on why the ReaderWriterLock isn't the best option: Low-Lock Techniques in action: Implementing a Reader-Writer lock Analysis of Reader-Writer lock...&lt;/p&gt;
</description></item><item><title>How to manage Control States in Silverlight Applications &amp;laquo; All about nothing</title><link>http://blogs.msdn.com/vancem/archive/2006/03/28/563180.aspx#9743216</link><pubDate>Sat, 13 Jun 2009 12:25:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9743216</guid><dc:creator>How to manage Control States in Silverlight Applications &amp;laquo; All about nothing</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://jachman.wordpress.com/2009/06/13/how-to-manage-control-states-in-silverlight-applications/"&gt;http://jachman.wordpress.com/2009/06/13/how-to-manage-control-states-in-silverlight-applications/&lt;/a&gt;&lt;/p&gt;
</description></item></channel></rss>