<?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: “Thread safe” Dictionary(TKey,TValue)</title>
	<atom:link href="http://www.grumpydev.com/2010/02/25/thread-safe-dictionarytkeytvalue/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.grumpydev.com/2010/02/25/thread-safe-dictionarytkeytvalue/</link>
	<description>The Technical Jibber Jabber of Steven Robbins</description>
	<lastBuildDate>Mon, 23 Aug 2010 13:25:21 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: So What Is This &#8220;Thread Safe&#8221; Thing Anyway? &#124; GrumpyDev</title>
		<link>http://www.grumpydev.com/2010/02/25/thread-safe-dictionarytkeytvalue/comment-page-1/#comment-185</link>
		<dc:creator>So What Is This &#8220;Thread Safe&#8221; Thing Anyway? &#124; GrumpyDev</dc:creator>
		<pubDate>Fri, 26 Feb 2010 10:25:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.grumpydev.com/?p=264#comment-185</guid>
		<description>[...] on from my previous post about a “Thread Safe” Dictionary, and the subsequent comment from Rajeesh, made me think that perhaps a general post on “thread [...]</description>
		<content:encoded><![CDATA[<p>[...] on from my previous post about a “Thread Safe” Dictionary, and the subsequent comment from Rajeesh, made me think that perhaps a general post on “thread [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: The Morning Brew - Chris Alcock &#187; The Morning Brew #548</title>
		<link>http://www.grumpydev.com/2010/02/25/thread-safe-dictionarytkeytvalue/comment-page-1/#comment-183</link>
		<dc:creator>The Morning Brew - Chris Alcock &#187; The Morning Brew #548</dc:creator>
		<pubDate>Fri, 26 Feb 2010 08:01:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.grumpydev.com/?p=264#comment-183</guid>
		<description>[...] &quot;Thread safe&quot; Dictionary(TKey,TValue) - GrumpyDev AKA Steven Robbins takes a look at implementing a Thread Safe Dictionary in .NET 3.5 for a pet project, with a view to moving his project to using the .NET 4 concurrent collections dictionary in the future. [...]</description>
		<content:encoded><![CDATA[<p>[...] &quot;Thread safe&quot; Dictionary(TKey,TValue) &#8211; GrumpyDev AKA Steven Robbins takes a look at implementing a Thread Safe Dictionary in .NET 3.5 for a pet project, with a view to moving his project to using the .NET 4 concurrent collections dictionary in the future. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: srobbins</title>
		<link>http://www.grumpydev.com/2010/02/25/thread-safe-dictionarytkeytvalue/comment-page-1/#comment-182</link>
		<dc:creator>srobbins</dc:creator>
		<pubDate>Fri, 26 Feb 2010 07:19:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.grumpydev.com/?p=264#comment-182</guid>
		<description>Hi Rajeesh,

Of course you are right, but this is generally the case with all &quot;thread safe&quot; classes. We can attempt to guarantee all of our public methods are safe to call concurrently from separate threads, but there&#039;s no way to ensure that *multiple calls* from one thread happen before calls from another. In this scenario you will require an external lock. 

The reason I generally use &quot;thread safe&quot; in quotes is partly for this reason. We can do our best to make our internals safe, but you still need to make sure that your calling code isn&#039;t doing anything inherently unsafe. 

The code you pasted won&#039;t error, you just might not end up with quite the value you expect, but even with your locks in place another thread may overwrite your new value immediately, so the lock in your example seems to add little value.

Thanks,

Steve </description>
		<content:encoded><![CDATA[<p>Hi Rajeesh,</p>
<p>Of course you are right, but this is generally the case with all &#8220;thread safe&#8221; classes. We can attempt to guarantee all of our public methods are safe to call concurrently from separate threads, but there&#8217;s no way to ensure that *multiple calls* from one thread happen before calls from another. In this scenario you will require an external lock. </p>
<p>The reason I generally use &#8220;thread safe&#8221; in quotes is partly for this reason. We can do our best to make our internals safe, but you still need to make sure that your calling code isn&#8217;t doing anything inherently unsafe. </p>
<p>The code you pasted won&#8217;t error, you just might not end up with quite the value you expect, but even with your locks in place another thread may overwrite your new value immediately, so the lock in your example seems to add little value.</p>
<p>Thanks,</p>
<p>Steve</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rajeesh</title>
		<link>http://www.grumpydev.com/2010/02/25/thread-safe-dictionarytkeytvalue/comment-page-1/#comment-181</link>
		<dc:creator>Rajeesh</dc:creator>
		<pubDate>Fri, 26 Feb 2010 06:36:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.grumpydev.com/?p=264#comment-181</guid>
		<description>Hi Steve,

What happens if somebody call the below code from multiple threads

if(safeDictionaryObj[&quot;MyKey&quot;] == &quot;SomeValue&quot;)
{
     safeDictionaryObj[&quot;MyKey&quot;] = &quot;NewValue&quot;;
}

It won&#039;t be working as expected, so we may have to lock the entire if statement again to make it thread safe.

lock(__alockobj)
{
   if(safeDictionaryObj[&quot;MyKey&quot;] == &quot;SomeValue&quot;)
   {
      safeDictionaryObj[&quot;MyKey&quot;] = &quot;NewValue&quot;;
    }
}

So the composition class you have created may not holds good for this scenario.</description>
		<content:encoded><![CDATA[<p>Hi Steve,</p>
<p>What happens if somebody call the below code from multiple threads</p>
<p>if(safeDictionaryObj["MyKey"] == &#8220;SomeValue&#8221;)<br />
{<br />
     safeDictionaryObj["MyKey"] = &#8220;NewValue&#8221;;<br />
}</p>
<p>It won&#8217;t be working as expected, so we may have to lock the entire if statement again to make it thread safe.</p>
<p>lock(__alockobj)<br />
{<br />
   if(safeDictionaryObj["MyKey"] == &#8220;SomeValue&#8221;)<br />
   {<br />
      safeDictionaryObj["MyKey"] = &#8220;NewValue&#8221;;<br />
    }<br />
}</p>
<p>So the composition class you have created may not holds good for this scenario.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
