<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/1.5.2" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Multi-threading Memory</title>
	<link>http://www.airs.com/blog/archives/151</link>
	<description>Ian Lance Taylor</description>
	<pubDate>Thu, 28 Aug 2008 07:12:02 +0000</pubDate>
	<generator>http://wordpress.org/?v=1.5.2</generator>

	<item>
 		<title>Comment on Multi-threading Memory by: Ian Lance Taylor</title>
		<link>http://www.airs.com/blog/archives/151#comment-11266</link>
		<pubDate>Tue, 04 Mar 2008 13:56:08 +0000</pubDate>
		<guid>http://www.airs.com/blog/archives/151#comment-11266</guid>
					<description>rdb: thanks for the pointer.

Simon: yes, I tend to think that a stream like interface for communicating between threads is the most workable method for multi-multi-core systems.  That idea &lt;a href=&quot;http://www.airs.com/blog/archives/92&quot; rel=&quot;nofollow&quot;&gt;came up earlier&lt;/a&gt; also.</description>
		<content:encoded><![CDATA[	<p>rdb: thanks for the pointer.</p>
	<p>Simon: yes, I tend to think that a stream like interface for communicating between threads is the most workable method for multi-multi-core systems.  That idea <a href="http://www.airs.com/blog/archives/92" rel="nofollow">came up earlier</a> also.
</p>
]]></content:encoded>
				</item>
	<item>
 		<title>Comment on Multi-threading Memory by: Simon Richter</title>
		<link>http://www.airs.com/blog/archives/151#comment-11265</link>
		<pubDate>Tue, 04 Mar 2008 09:29:02 +0000</pubDate>
		<guid>http://www.airs.com/blog/archives/151#comment-11265</guid>
					<description>Good point -- so the current implementations do not really behave like single abstract machines operating concurrently, and my model of thinking is wrong (good thing I never share more than an unsigned int for progress reports between two threads :-) ).

The question is: can this be fixed without imposing undue overhead?

If writes to shared variables should be visible in-order, the implementation would have to insert memory barriers, which is an OS-specific thing (so the compiler would have to be OS aware). If it were to do this implicitly, it'd have to guess and err on the side of caution, degrading performance. If the programmer had to insert the barriers, there is no gain compared to the status quo.

Shared memory between threads seems to be a bad idea altogether. I wonder if it would make more sense to have a &quot;stream&quot; like interface that an implementation could map to shared memory if it could guarantee consistency, but were not required to if other methods made more sense (for example, for NUMA).</description>
		<content:encoded><![CDATA[	<p>Good point &#8212; so the current implementations do not really behave like single abstract machines operating concurrently, and my model of thinking is wrong (good thing I never share more than an unsigned int for progress reports between two threads <img src='http://www.airs.com/blog/wp-images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  ).</p>
	<p>The question is: can this be fixed without imposing undue overhead?</p>
	<p>If writes to shared variables should be visible in-order, the implementation would have to insert memory barriers, which is an OS-specific thing (so the compiler would have to be OS aware). If it were to do this implicitly, it&#8217;d have to guess and err on the side of caution, degrading performance. If the programmer had to insert the barriers, there is no gain compared to the status quo.</p>
	<p>Shared memory between threads seems to be a bad idea altogether. I wonder if it would make more sense to have a &#8220;stream&#8221; like interface that an implementation could map to shared memory if it could guarantee consistency, but were not required to if other methods made more sense (for example, for NUMA).
</p>
]]></content:encoded>
				</item>
	<item>
 		<title>Comment on Multi-threading Memory by: rdb</title>
		<link>http://www.airs.com/blog/archives/151#comment-11256</link>
		<pubDate>Tue, 04 Mar 2008 00:39:43 +0000</pubDate>
		<guid>http://www.airs.com/blog/archives/151#comment-11256</guid>
					<description>&lt;a href=&quot;http://linux.conf.au/programme/detail?TalkID=240&quot; rel=&quot;nofollow&quot;&gt;Paul McKenney&lt;/a&gt;'s LCA2008 talk &quot;After 25 Years, C/C++ Understands Concurrency&quot; on this has slides, video &amp;#38; audio up on the Friday program link.  (2nd try, only the one URL this time).</description>
		<content:encoded><![CDATA[	<p><a href="http://linux.conf.au/programme/detail?TalkID=240" rel="nofollow">Paul McKenney</a>&#8217;s LCA2008 talk &#8220;After 25 Years, C/C++ Understands Concurrency&#8221; on this has slides, video &amp; audio up on the Friday program link.  (2nd try, only the one URL this time).
</p>
]]></content:encoded>
				</item>
	<item>
 		<title>Comment on Multi-threading Memory by: Ian Lance Taylor</title>
		<link>http://www.airs.com/blog/archives/151#comment-11249</link>
		<pubDate>Mon, 03 Mar 2008 22:39:05 +0000</pubDate>
		<guid>http://www.airs.com/blog/archives/151#comment-11249</guid>
					<description>Thanks for the comment.

volatile doesn't help all that much.  In particular, if you have two volatile global variables, and one thread changes first A and then B, there is no guarantee that a thread running on a different core will see the changes in that order.  It might very sell see the change to B before it sees the change to A.  volatile only applies within a single thread, it does not imply anything about threads running on multiple cores.</description>
		<content:encoded><![CDATA[	<p>Thanks for the comment.</p>
	<p>volatile doesn&#8217;t help all that much.  In particular, if you have two volatile global variables, and one thread changes first A and then B, there is no guarantee that a thread running on a different core will see the changes in that order.  It might very sell see the change to B before it sees the change to A.  volatile only applies within a single thread, it does not imply anything about threads running on multiple cores.
</p>
]]></content:encoded>
				</item>
	<item>
 		<title>Comment on Multi-threading Memory by: Simon Richter</title>
		<link>http://www.airs.com/blog/archives/151#comment-11183</link>
		<pubDate>Sat, 01 Mar 2008 14:28:35 +0000</pubDate>
		<guid>http://www.airs.com/blog/archives/151#comment-11183</guid>
					<description>I still think that &quot;volatile&quot; serves us quite well here.

When I write multi-threaded programs, rather than thinking of a single abstract machine with multiple threads, I think of multiple abstract machines that can see exactly each other's &quot;observable behaviour&quot;, which is well-defined in the standard, and nothing else.

Guaranteed atomic types were something I sorely missed in the standard -- I just assumed that &quot;unsigned int&quot; was atomic for all purposes, which I believe holds true in most if not all implementations. My only use for them, however, is reporting progress when one thread is handling I/O and the other is doing a lengthy computation.

The new standard essentially codifies existing practice in treating everything like I/O buffers (i.e. accesses aren't ordered, but are guaranteed to happen) unless told otherwise. Since the overwhelming majority of objects in my programs aren't shared, I'd actually prefer explicitly marking those that are (that takes quite a few load/store instructions out of the hot path), however that would break lots of existing code.</description>
		<content:encoded><![CDATA[	<p>I still think that &#8220;volatile&#8221; serves us quite well here.</p>
	<p>When I write multi-threaded programs, rather than thinking of a single abstract machine with multiple threads, I think of multiple abstract machines that can see exactly each other&#8217;s &#8220;observable behaviour&#8221;, which is well-defined in the standard, and nothing else.</p>
	<p>Guaranteed atomic types were something I sorely missed in the standard &#8212; I just assumed that &#8220;unsigned int&#8221; was atomic for all purposes, which I believe holds true in most if not all implementations. My only use for them, however, is reporting progress when one thread is handling I/O and the other is doing a lengthy computation.</p>
	<p>The new standard essentially codifies existing practice in treating everything like I/O buffers (i.e. accesses aren&#8217;t ordered, but are guaranteed to happen) unless told otherwise. Since the overwhelming majority of objects in my programs aren&#8217;t shared, I&#8217;d actually prefer explicitly marking those that are (that takes quite a few load/store instructions out of the hot path), however that would break lots of existing code.
</p>
]]></content:encoded>
				</item>
</channel>
</rss>
