<?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: A Short Guide to Mastering Thread-Safety</title>
	<atom:link href="http://www.thinkingparallel.com/2006/10/15/a-short-guide-to-mastering-thread-safety/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thinkingparallel.com/2006/10/15/a-short-guide-to-mastering-thread-safety/</link>
	<description>A Blog on Parallel Programming and Concurrency by Michael Suess</description>
	<pubDate>Fri, 12 Mar 2010 00:38:41 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Doug</title>
		<link>http://www.thinkingparallel.com/2006/10/15/a-short-guide-to-mastering-thread-safety/comment-page-1/#comment-71401</link>
		<dc:creator>Doug</dc:creator>
		<pubDate>Mon, 21 Jul 2008 17:48:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.thinkingparallel.com/2006/10/15/a-short-guide-to-mastering-thread-safety/#comment-71401</guid>
		<description>Rachna atomic data is not thread safe when you write to the atomic data because of CPU memory caching issues.  Read only is safe because the cached data is always the same as what exists in memory.  Even if you have atomic variables you must mark them as volatile and access them in a critical section or some other locking mechanism if you wish to update them.</description>
		<content:encoded><![CDATA[<p>Rachna atomic data is not thread safe when you write to the atomic data because of CPU memory caching issues.  Read only is safe because the cached data is always the same as what exists in memory.  Even if you have atomic variables you must mark them as volatile and access them in a critical section or some other locking mechanism if you wish to update them.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Suess</title>
		<link>http://www.thinkingparallel.com/2006/10/15/a-short-guide-to-mastering-thread-safety/comment-page-1/#comment-71141</link>
		<dc:creator>Michael Suess</dc:creator>
		<pubDate>Sun, 20 Jul 2008 13:13:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.thinkingparallel.com/2006/10/15/a-short-guide-to-mastering-thread-safety/#comment-71141</guid>
		<description>It could be true, depending on the memory model of the particular threading-system you are using. But believe me, you probably don't want to rely on stuff as low-level as this, because its very easy to introduce mistakes there.</description>
		<content:encoded><![CDATA[<p>It could be true, depending on the memory model of the particular threading-system you are using. But believe me, you probably don&#8217;t want to rely on stuff as low-level as this, because its very easy to introduce mistakes there.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rachna</title>
		<link>http://www.thinkingparallel.com/2006/10/15/a-short-guide-to-mastering-thread-safety/comment-page-1/#comment-70606</link>
		<dc:creator>Rachna</dc:creator>
		<pubDate>Thu, 17 Jul 2008 04:34:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.thinkingparallel.com/2006/10/15/a-short-guide-to-mastering-thread-safety/#comment-70606</guid>
		<description>I heard somewhere that if the data that is being shared by different threads is atomic, there is not need to use locks and that it will be automatically thread safe. Is this true? If it is, then please tell me what are the atomic data types available in VC++? Are atomic data types always threadsafe regardless of whether its used on 32-bit OS of 64-bit OS?</description>
		<content:encoded><![CDATA[<p>I heard somewhere that if the data that is being shared by different threads is atomic, there is not need to use locks and that it will be automatically thread safe. Is this true? If it is, then please tell me what are the atomic data types available in VC++? Are atomic data types always threadsafe regardless of whether its used on 32-bit OS of 64-bit OS?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Doug</title>
		<link>http://www.thinkingparallel.com/2006/10/15/a-short-guide-to-mastering-thread-safety/comment-page-1/#comment-43161</link>
		<dc:creator>Doug</dc:creator>
		<pubDate>Tue, 29 Jan 2008 23:22:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.thinkingparallel.com/2006/10/15/a-short-guide-to-mastering-thread-safety/#comment-43161</guid>
		<description>Or create worker threads that only read shared data and write to their own memory.  Threading is much easier when threads don't talk to each other and when everything they share is read only.</description>
		<content:encoded><![CDATA[<p>Or create worker threads that only read shared data and write to their own memory.  Threading is much easier when threads don&#8217;t talk to each other and when everything they share is read only.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Leniel Macaferi</title>
		<link>http://www.thinkingparallel.com/2006/10/15/a-short-guide-to-mastering-thread-safety/comment-page-1/#comment-39072</link>
		<dc:creator>Leniel Macaferi</dc:creator>
		<pubDate>Sun, 06 Jan 2008 18:55:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.thinkingparallel.com/2006/10/15/a-short-guide-to-mastering-thread-safety/#comment-39072</guid>
		<description>Hello,

I'm also implementing a thread safe circular queue and as far as I went the only way I could achieve that was using locks.

So I got the first option of the listing discussed in this post: put a big, fat lock right at the start of the function and unlock it at the end of the function.

By the way Michael, your post is really enlightening.

Leniel Macaferi</description>
		<content:encoded><![CDATA[<p>Hello,</p>
<p>I&#8217;m also implementing a thread safe circular queue and as far as I went the only way I could achieve that was using locks.</p>
<p>So I got the first option of the listing discussed in this post: put a big, fat lock right at the start of the function and unlock it at the end of the function.</p>
<p>By the way Michael, your post is really enlightening.</p>
<p>Leniel Macaferi</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Brock</title>
		<link>http://www.thinkingparallel.com/2006/10/15/a-short-guide-to-mastering-thread-safety/comment-page-1/#comment-14231</link>
		<dc:creator>James Brock</dc:creator>
		<pubDate>Wed, 20 Jun 2007 05:54:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.thinkingparallel.com/2006/10/15/a-short-guide-to-mastering-thread-safety/#comment-14231</guid>
		<description>Vivek, your thread-safe circular queue that leverages atomic increment-and-return integer operations is possible--if you only allow two threads. I tried to write a general thread-safe constant-time circular queue in C# using System.Threading.Interlocked. I thought I had it perfected, but my unit test kept failing. It took me a long time to discover the case for which it fails, and it is a case that I have no answer for:

1. Thread A enters Enqueue
2. Thread B enters Enqueue
3. Thread B exits Enqueue
4. Thread C enters Dequeue
5. Thread C exits Dequeue
6. Thread A exits Enqueue

Thread C will Dequeue a nonsense value because thread A has not yet written to the underlying array, but thread B has already incremented the queue pointer.

In general, your data structure will not be thread safe if you have three or more threads executing the Enqueue and Dequeue methods at different speeds. You must either abandon constant-time or use locks.</description>
		<content:encoded><![CDATA[<p>Vivek, your thread-safe circular queue that leverages atomic increment-and-return integer operations is possible&#8211;if you only allow two threads. I tried to write a general thread-safe constant-time circular queue in C# using System.Threading.Interlocked. I thought I had it perfected, but my unit test kept failing. It took me a long time to discover the case for which it fails, and it is a case that I have no answer for:</p>
<p>1. Thread A enters Enqueue<br />
2. Thread B enters Enqueue<br />
3. Thread B exits Enqueue<br />
4. Thread C enters Dequeue<br />
5. Thread C exits Dequeue<br />
6. Thread A exits Enqueue</p>
<p>Thread C will Dequeue a nonsense value because thread A has not yet written to the underlying array, but thread B has already incremented the queue pointer.</p>
<p>In general, your data structure will not be thread safe if you have three or more threads executing the Enqueue and Dequeue methods at different speeds. You must either abandon constant-time or use locks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dieter an Mey</title>
		<link>http://www.thinkingparallel.com/2006/10/15/a-short-guide-to-mastering-thread-safety/comment-page-1/#comment-74</link>
		<dc:creator>Dieter an Mey</dc:creator>
		<pubDate>Thu, 23 Nov 2006 16:21:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.thinkingparallel.com/2006/10/15/a-short-guide-to-mastering-thread-safety/#comment-74</guid>
		<description>The problem with a lack of thread-safty is that data races may not appear during a thousand program runs, but then suddenly they do occur and cause the program to deliver wrong results or crash.

A good idea to make a buggy program fail earlier is to start it on a machine which has less processors (or cores) then you are employing threads.

So a single processor box may be a good platform for debugging (if your threads do not use spin-waiting, in which case the program may take a while ... )</description>
		<content:encoded><![CDATA[<p>The problem with a lack of thread-safty is that data races may not appear during a thousand program runs, but then suddenly they do occur and cause the program to deliver wrong results or crash.</p>
<p>A good idea to make a buggy program fail earlier is to start it on a machine which has less processors (or cores) then you are employing threads.</p>
<p>So a single processor box may be a good platform for debugging (if your threads do not use spin-waiting, in which case the program may take a while &#8230; )</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Suess</title>
		<link>http://www.thinkingparallel.com/2006/10/15/a-short-guide-to-mastering-thread-safety/comment-page-1/#comment-68</link>
		<dc:creator>Michael Suess</dc:creator>
		<pubDate>Wed, 08 Nov 2006 08:48:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.thinkingparallel.com/2006/10/15/a-short-guide-to-mastering-thread-safety/#comment-68</guid>
		<description>@Vivek: I have not mentioned lock-free data structures, because I don't consider them safe for use (not to mention portable) yet, except when hidden from the user in a well-implemented library. I will probaby write an article about these some time later, though.

@Lionell: I am not sure I understand your comment. I am not only discussing multi-processing issues, I am discussing multi-threading issues. And I do know that the problems I have outlined do happen on single-processor machines, as the scheduler is free to preempt threads at any time. Will try to make that more clear in future articles...</description>
		<content:encoded><![CDATA[<p>@Vivek: I have not mentioned lock-free data structures, because I don&#8217;t consider them safe for use (not to mention portable) yet, except when hidden from the user in a well-implemented library. I will probaby write an article about these some time later, though.</p>
<p>@Lionell: I am not sure I understand your comment. I am not only discussing multi-processing issues, I am discussing multi-threading issues. And I do know that the problems I have outlined do happen on single-processor machines, as the scheduler is free to preempt threads at any time. Will try to make that more clear in future articles&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lionell Griffith</title>
		<link>http://www.thinkingparallel.com/2006/10/15/a-short-guide-to-mastering-thread-safety/comment-page-1/#comment-65</link>
		<dc:creator>Lionell Griffith</dc:creator>
		<pubDate>Mon, 06 Nov 2006 13:41:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.thinkingparallel.com/2006/10/15/a-short-guide-to-mastering-thread-safety/#comment-65</guid>
		<description>I suggest that you shift your thinking to dealing with shared resources.  Its not only memory and code that's involved.  Its not only parallel processing that has the problem.  Preemptive multi-tasking/threading also is challenged by shared resource access even on a single core CPU.  

I know you think you are discussing ONLY multi-processing issues. Preemptive multi-tasking/threading has EXACTLY the same set of issue that are best dealt with by EXACTLY the same set of strategies suitable for parallel processing.  Solve the shared resource contention issues for one domain and you have solved them for the other.  
The only necessary implementation difference between the two domains is the assignment of priorities to threads in a single CPU and assignment of threads to specific CPU's in multi-processing systems.

I suspect the challenge is that few people programming today have ever had to deal with multi-priority real-time interrupt-driven data-acquisition and process-control systems.  Especially ones on room sized computers with less compute power than your typical digital watch.</description>
		<content:encoded><![CDATA[<p>I suggest that you shift your thinking to dealing with shared resources.  Its not only memory and code that&#8217;s involved.  Its not only parallel processing that has the problem.  Preemptive multi-tasking/threading also is challenged by shared resource access even on a single core CPU.  </p>
<p>I know you think you are discussing ONLY multi-processing issues. Preemptive multi-tasking/threading has EXACTLY the same set of issue that are best dealt with by EXACTLY the same set of strategies suitable for parallel processing.  Solve the shared resource contention issues for one domain and you have solved them for the other.<br />
The only necessary implementation difference between the two domains is the assignment of priorities to threads in a single CPU and assignment of threads to specific CPU&#8217;s in multi-processing systems.</p>
<p>I suspect the challenge is that few people programming today have ever had to deal with multi-priority real-time interrupt-driven data-acquisition and process-control systems.  Especially ones on room sized computers with less compute power than your typical digital watch.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stefan</title>
		<link>http://www.thinkingparallel.com/2006/10/15/a-short-guide-to-mastering-thread-safety/comment-page-1/#comment-62</link>
		<dc:creator>Stefan</dc:creator>
		<pubDate>Mon, 30 Oct 2006 07:34:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.thinkingparallel.com/2006/10/15/a-short-guide-to-mastering-thread-safety/#comment-62</guid>
		<description>I wouldn't expect reading about W. Ostwald on a website like this. Good translation (as far as I can evaluate this). You got the point so far. Now I'm looking forward to the next article on that. And to which extent the word 'may' will guide you again *g*.</description>
		<content:encoded><![CDATA[<p>I wouldn&#8217;t expect reading about W. Ostwald on a website like this. Good translation (as far as I can evaluate this). You got the point so far. Now I&#8217;m looking forward to the next article on that. And to which extent the word &#8216;may&#8217; will guide you again *g*.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
