<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	>
<channel>
	<title>Comments on: The empty try block mystery</title>
	<atom:link href="http://blog.somecreativity.com/2008/04/10/the-empty-try-block-mystery/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.somecreativity.com/2008/04/10/the-empty-try-block-mystery/</link>
	<description>Weblog of Siddharth Uppal</description>
	<pubDate>Fri, 21 Nov 2008 17:15:31 +0000</pubDate>
	<generator>http://wordpress.org/?v=MU</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Tom</title>
		<link>http://blog.somecreativity.com/2008/04/10/the-empty-try-block-mystery/#comment-4690</link>
		<dc:creator>Tom</dc:creator>
		<pubDate>Mon, 30 Jun 2008 06:43:19 +0000</pubDate>
		<guid isPermaLink="false">http://siddhu.wordpress.com/?p=467#comment-4690</guid>
		<description>Thanks Siddharth, helped a lot.</description>
		<content:encoded><![CDATA[<p>Thanks Siddharth, helped a lot.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: C# compiler optimizations and empty “try” block &#171; Some Creativity</title>
		<link>http://blog.somecreativity.com/2008/04/10/the-empty-try-block-mystery/#comment-4676</link>
		<dc:creator>C# compiler optimizations and empty “try” block &#171; Some Creativity</dc:creator>
		<pubDate>Tue, 29 Apr 2008 00:47:39 +0000</pubDate>
		<guid isPermaLink="false">http://siddhu.wordpress.com/?p=467#comment-4676</guid>
		<description>[...] why you would have a try/finally with an empty “try” in the first place, you might find an earlier article of mine [...]</description>
		<content:encoded><![CDATA[<p>[...] why you would have a try/finally with an empty “try” in the first place, you might find an earlier article of mine [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: igorbrejc.net &#187; Friday Goodies - 18. March</title>
		<link>http://blog.somecreativity.com/2008/04/10/the-empty-try-block-mystery/#comment-4658</link>
		<dc:creator>igorbrejc.net &#187; Friday Goodies - 18. March</dc:creator>
		<pubDate>Fri, 18 Apr 2008 08:00:47 +0000</pubDate>
		<guid isPermaLink="false">http://siddhu.wordpress.com/?p=467#comment-4658</guid>
		<description>[...] The empty try block mystery [...]</description>
		<content:encoded><![CDATA[<p>[...] The empty try block mystery [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Guy</title>
		<link>http://blog.somecreativity.com/2008/04/10/the-empty-try-block-mystery/#comment-4657</link>
		<dc:creator>Guy</dc:creator>
		<pubDate>Wed, 16 Apr 2008 14:03:09 +0000</pubDate>
		<guid isPermaLink="false">http://siddhu.wordpress.com/?p=467#comment-4657</guid>
		<description>Great post</description>
		<content:encoded><![CDATA[<p>Great post</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Interesting Finds: 2008.04.16 - gOODiDEA.NET</title>
		<link>http://blog.somecreativity.com/2008/04/10/the-empty-try-block-mystery/#comment-4656</link>
		<dc:creator>Interesting Finds: 2008.04.16 - gOODiDEA.NET</dc:creator>
		<pubDate>Wed, 16 Apr 2008 03:58:26 +0000</pubDate>
		<guid isPermaLink="false">http://siddhu.wordpress.com/?p=467#comment-4656</guid>
		<description>[...] The empty try block mystery [...]</description>
		<content:encoded><![CDATA[<p>[...] The empty try block mystery [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Reflective Perspective - Chris Alcock &#187; The Morning Brew #73</title>
		<link>http://blog.somecreativity.com/2008/04/10/the-empty-try-block-mystery/#comment-4650</link>
		<dc:creator>Reflective Perspective - Chris Alcock &#187; The Morning Brew #73</dc:creator>
		<pubDate>Tue, 15 Apr 2008 06:47:35 +0000</pubDate>
		<guid isPermaLink="false">http://siddhu.wordpress.com/?p=467#comment-4650</guid>
		<description>[...] The empty try block mystery - Siddharth Uppal highlights an interesting tip discovered by reading the .NET Framework code. [...]</description>
		<content:encoded><![CDATA[<p>[...] The empty try block mystery - Siddharth Uppal highlights an interesting tip discovered by reading the .NET Framework code. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: regev</title>
		<link>http://blog.somecreativity.com/2008/04/10/the-empty-try-block-mystery/#comment-4646</link>
		<dc:creator>regev</dc:creator>
		<pubDate>Sun, 13 Apr 2008 06:50:50 +0000</pubDate>
		<guid isPermaLink="false">http://siddhu.wordpress.com/?p=467#comment-4646</guid>
		<description>Thanks for this enlightening post.</description>
		<content:encoded><![CDATA[<p>Thanks for this enlightening post.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sid</title>
		<link>http://blog.somecreativity.com/2008/04/10/the-empty-try-block-mystery/#comment-4645</link>
		<dc:creator>Sid</dc:creator>
		<pubDate>Fri, 11 Apr 2008 18:11:38 +0000</pubDate>
		<guid isPermaLink="false">http://siddhu.wordpress.com/?p=467#comment-4645</guid>
		<description>Thanks everyone for comments. It's encouraging :)

@Will,

"finally" isn't a critical section by itself. In general, you can have two threads executing the finally block of the same method at the same time. However, "lock" uses "try" and "finally" under the hood. 

The following piece of code:

lock(orange)
{
    DoSomething();
}

... is munged by the compiler to IL achieving the following:

Monitor.Enter(orange);
try 
{
    DoSomething();
}
finally
{
    Monitor.Exit(orange);
}

So you are right in that, the "finally" generated by the compiler when it sees "lock" is a critical section because of the Monitor.Enter call that preceded it. But I'm not sure if you were thinking that deep :) "finally" isn't a critical section on its own.

As for other alternatives to "lock", one could use any of Monitor, Mutex or Semaphore to implement critical sections. Not sure if you were referring to them.</description>
		<content:encoded><![CDATA[<p>Thanks everyone for comments. It&#8217;s encouraging <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>@Will,</p>
<p>&#8220;finally&#8221; isn&#8217;t a critical section by itself. In general, you can have two threads executing the finally block of the same method at the same time. However, &#8220;lock&#8221; uses &#8220;try&#8221; and &#8220;finally&#8221; under the hood. </p>
<p>The following piece of code:</p>
<p>lock(orange)<br />
{<br />
    DoSomething();<br />
}</p>
<p>&#8230; is munged by the compiler to IL achieving the following:</p>
<p>Monitor.Enter(orange);<br />
try<br />
{<br />
    DoSomething();<br />
}<br />
finally<br />
{<br />
    Monitor.Exit(orange);<br />
}</p>
<p>So you are right in that, the &#8220;finally&#8221; generated by the compiler when it sees &#8220;lock&#8221; is a critical section because of the Monitor.Enter call that preceded it. But I&#8217;m not sure if you were thinking that deep <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> &#8220;finally&#8221; isn&#8217;t a critical section on its own.</p>
<p>As for other alternatives to &#8220;lock&#8221;, one could use any of Monitor, Mutex or Semaphore to implement critical sections. Not sure if you were referring to them.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Will</title>
		<link>http://blog.somecreativity.com/2008/04/10/the-empty-try-block-mystery/#comment-4644</link>
		<dc:creator>Will</dc:creator>
		<pubDate>Fri, 11 Apr 2008 17:31:20 +0000</pubDate>
		<guid isPermaLink="false">http://siddhu.wordpress.com/?p=467#comment-4644</guid>
		<description>The finally{} block is a critical section.  There are other ways of creating critical sections, such as using lock().  I know lock won't keep a thread from aborting, but I believe there is another way to mark a section as critical that will keep the thread abort monster away.  But I don't have my CLR Via C# handy and can't remember it.

This is also an example why you need to be VERY careful of what you do in a finally block.  If you get into a race condition within one, good luck recovering.</description>
		<content:encoded><![CDATA[<p>The finally{} block is a critical section.  There are other ways of creating critical sections, such as using lock().  I know lock won&#8217;t keep a thread from aborting, but I believe there is another way to mark a section as critical that will keep the thread abort monster away.  But I don&#8217;t have my CLR Via C# handy and can&#8217;t remember it.</p>
<p>This is also an example why you need to be VERY careful of what you do in a finally block.  If you get into a race condition within one, good luck recovering.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Igor</title>
		<link>http://blog.somecreativity.com/2008/04/10/the-empty-try-block-mystery/#comment-4643</link>
		<dc:creator>Igor</dc:creator>
		<pubDate>Fri, 11 Apr 2008 15:16:39 +0000</pubDate>
		<guid isPermaLink="false">http://siddhu.wordpress.com/?p=467#comment-4643</guid>
		<description>Cool!</description>
		<content:encoded><![CDATA[<p>Cool!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
