<?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: Atomic cargo cults</title>
	<atom:link href="http://digitalvampire.org/blog/index.php/2007/05/13/atomic-cargo-cults/feed/" rel="self" type="application/rss+xml" />
	<link>http://digitalvampire.org/blog/index.php/2007/05/13/atomic-cargo-cults/</link>
	<description>Linux hacker, recovering mathematician, former athlete</description>
	<lastBuildDate>Wed, 25 Aug 2010 23:50:28 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: roland</title>
		<link>http://digitalvampire.org/blog/index.php/2007/05/13/atomic-cargo-cults/comment-page-1/#comment-375</link>
		<dc:creator>roland</dc:creator>
		<pubDate>Sun, 18 Nov 2007 04:09:21 +0000</pubDate>
		<guid isPermaLink="false">http://digitalvampire.org/blog/index.php/2007/05/13/atomic-cargo-cults/#comment-375</guid>
		<description>Narty: see the comments above, which discuss the fact that atomic_t is not volatile on x86 at least.</description>
		<content:encoded><![CDATA[<p>Narty: see the comments above, which discuss the fact that atomic_t is not volatile on x86 at least.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Narty Atomic</title>
		<link>http://digitalvampire.org/blog/index.php/2007/05/13/atomic-cargo-cults/comment-page-1/#comment-373</link>
		<dc:creator>Narty Atomic</dc:creator>
		<pubDate>Fri, 16 Nov 2007 14:50:05 +0000</pubDate>
		<guid isPermaLink="false">http://digitalvampire.org/blog/index.php/2007/05/13/atomic-cargo-cults/#comment-373</guid>
		<description>The other side effect of using atomic_t is that your variable becomes volatile, which may have an important effect on the compiled code.</description>
		<content:encoded><![CDATA[<p>The other side effect of using atomic_t is that your variable becomes volatile, which may have an important effect on the compiled code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Roland&#8217;s Blog &#187; Blog Archive</title>
		<link>http://digitalvampire.org/blog/index.php/2007/05/13/atomic-cargo-cults/comment-page-1/#comment-85</link>
		<dc:creator>Roland&#8217;s Blog &#187; Blog Archive</dc:creator>
		<pubDate>Wed, 06 Jun 2007 03:17:20 +0000</pubDate>
		<guid isPermaLink="false">http://digitalvampire.org/blog/index.php/2007/05/13/atomic-cargo-cults/#comment-85</guid>
		<description>[...] Zaitcev replied to my earlier post about misuse of atomic variables. I never really thought of myself as a crusader or as particularly [...]</description>
		<content:encoded><![CDATA[<p>[...] Zaitcev replied to my earlier post about misuse of atomic variables. I never really thought of myself as a crusader or as particularly [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh Stone</title>
		<link>http://digitalvampire.org/blog/index.php/2007/05/13/atomic-cargo-cults/comment-page-1/#comment-16</link>
		<dc:creator>Josh Stone</dc:creator>
		<pubDate>Mon, 14 May 2007 16:06:36 +0000</pubDate>
		<guid isPermaLink="false">http://digitalvampire.org/blog/index.php/2007/05/13/atomic-cargo-cults/#comment-16</guid>
		<description>Well, I was pretty sure atomic_t was volatile, so you got me to do some research.  It looks like this was a fairly recent change.  The log for f9e9dcb38f5106fa8cdac04a9e967d5487f1cd20 in git reads thus:

&lt;blockquote&gt;x86[-64]:Remove &#039;volatile&#039; from atomic_t
Linus Torvalds [Wed, 6 Dec 2006 22:42:57 +0000 (14:42 -0800)]
Any code that relies on the volatile would be a bug waiting to happen
anyway.

Don&#039;t encourage people to think that putting &#039;volatile&#039; on data
structures somehow fixes problems.  We should always use proper locking
(and other serialization) techniques.&lt;/blockquote&gt;

Thanks for the pointer to the &quot;volatile considered harmful&quot; discussion.  That addition to the documentation looks very worthwhile.

Many other architectures still do have volatile on their atomic_t typedef.  Is this because Linus hasn&#039;t gotten around to fixing those yet, or is there some reason that volatile is more appropriate on other architectures?

A final note about the atomicity of reading and writing ints -- your post about __attribute__((packed)) shows how this assumption sometimes doesn&#039;t hold.  If someone put an atomic_t inside a packed structure, then all bets are off, right?  That would surely be a bug, but perhaps atomic_t should have an __attribute__((aligned))?</description>
		<content:encoded><![CDATA[<p>Well, I was pretty sure atomic_t was volatile, so you got me to do some research.  It looks like this was a fairly recent change.  The log for f9e9dcb38f5106fa8cdac04a9e967d5487f1cd20 in git reads thus:</p>
<blockquote><p>x86[-64]:Remove &#8216;volatile&#8217; from atomic_t<br />
Linus Torvalds [Wed, 6 Dec 2006 22:42:57 +0000 (14:42 -0800)]<br />
Any code that relies on the volatile would be a bug waiting to happen<br />
anyway.</p>
<p>Don&#8217;t encourage people to think that putting &#8216;volatile&#8217; on data<br />
structures somehow fixes problems.  We should always use proper locking<br />
(and other serialization) techniques.</p></blockquote>
<p>Thanks for the pointer to the &#8220;volatile considered harmful&#8221; discussion.  That addition to the documentation looks very worthwhile.</p>
<p>Many other architectures still do have volatile on their atomic_t typedef.  Is this because Linus hasn&#8217;t gotten around to fixing those yet, or is there some reason that volatile is more appropriate on other architectures?</p>
<p>A final note about the atomicity of reading and writing ints &#8212; your post about __attribute__((packed)) shows how this assumption sometimes doesn&#8217;t hold.  If someone put an atomic_t inside a packed structure, then all bets are off, right?  That would surely be a bug, but perhaps atomic_t should have an __attribute__((aligned))?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: roland</title>
		<link>http://digitalvampire.org/blog/index.php/2007/05/13/atomic-cargo-cults/comment-page-1/#comment-14</link>
		<dc:creator>roland</dc:creator>
		<pubDate>Mon, 14 May 2007 03:37:06 +0000</pubDate>
		<guid isPermaLink="false">http://digitalvampire.org/blog/index.php/2007/05/13/atomic-cargo-cults/#comment-14</guid>
		<description>Josh: thanks for the comments.  Let me address them in reverse order.

You say that using atomic_t makes your variable volatile.  This is not true: on mainstream architectures such as i386 and x86_64, &lt;asm/atomic.h&gt; has

        typedef struct { int counter; } atomic_t;

with no volatile in sight.  In any case, the recent thread on LKML about adding documentation about &quot;volatile considered harmful&quot; to the kernel shows that in almost all cases, you don&#039;t want your variable to be declared volatile anyway.  When reviewing code, I can be pretty sure that an explicit &quot;volatile&quot; declaration is either unnecessary or marking a bug.

As far as assuming that reading and writing an int are atomic, I think that   assumption is pretty deeply ingrained in the Linux implementation.  Just about every lock-free algorithm that uses memory barriers is implicitly assuming that it will never read a half-written value.  And certainly every implementation of atomic_read() for all Linux architectures boils down to a simple read of an int.

So no, I don&#039;t think that &quot;abstracted atomicity&quot; is a reason to use atomic_t.

(BTW, It is legitimate to use atomic_t and atomic_set() if you are also using atomic bit ops)</description>
		<content:encoded><![CDATA[<p>Josh: thanks for the comments.  Let me address them in reverse order.</p>
<p>You say that using atomic_t makes your variable volatile.  This is not true: on mainstream architectures such as i386 and x86_64, <asm /atomic.h> has</p>
<p>        typedef struct { int counter; } atomic_t;</p>
<p>with no volatile in sight.  In any case, the recent thread on LKML about adding documentation about &#8220;volatile considered harmful&#8221; to the kernel shows that in almost all cases, you don&#8217;t want your variable to be declared volatile anyway.  When reviewing code, I can be pretty sure that an explicit &#8220;volatile&#8221; declaration is either unnecessary or marking a bug.</p>
<p>As far as assuming that reading and writing an int are atomic, I think that   assumption is pretty deeply ingrained in the Linux implementation.  Just about every lock-free algorithm that uses memory barriers is implicitly assuming that it will never read a half-written value.  And certainly every implementation of atomic_read() for all Linux architectures boils down to a simple read of an int.</p>
<p>So no, I don&#8217;t think that &#8220;abstracted atomicity&#8221; is a reason to use atomic_t.</p>
<p>(BTW, It is legitimate to use atomic_t and atomic_set() if you are also using atomic bit ops)</asm></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh Stone</title>
		<link>http://digitalvampire.org/blog/index.php/2007/05/13/atomic-cargo-cults/comment-page-1/#comment-12</link>
		<dc:creator>Josh Stone</dc:creator>
		<pubDate>Sun, 13 May 2007 19:00:34 +0000</pubDate>
		<guid isPermaLink="false">http://digitalvampire.org/blog/index.php/2007/05/13/atomic-cargo-cults/#comment-12</guid>
		<description>I won&#039;t argue that your examples are acceptable code -- the inc-mod especially makes me sad.  But consider the following:

The only reason atomic_set() and atomic_read() are useless here is because you&#039;re assuming that reading or writing an int is always an atomic operation.  This is probably true of the architectures you care about, but can you really say that this will be true for all architectures?  Using atomic_t explicitly declares the need for the assignment to be atomic, where that abstraction may then do whatever is necessary on every architecture.

The other side effect of using atomic_t is that your variable becomes volatile, which may have an important effect on the compiled code.

So you gain abstracted atomicity and volatileness.  Are you still willing to say that this isn&#039;t worthwhile?  Or is it just that this need is outside of what you consider &quot;the vast majority of the time&quot;?

PS - I hope you&#039;ll excuse my pedantry for the sake of argument :)</description>
		<content:encoded><![CDATA[<p>I won&#8217;t argue that your examples are acceptable code &#8212; the inc-mod especially makes me sad.  But consider the following:</p>
<p>The only reason atomic_set() and atomic_read() are useless here is because you&#8217;re assuming that reading or writing an int is always an atomic operation.  This is probably true of the architectures you care about, but can you really say that this will be true for all architectures?  Using atomic_t explicitly declares the need for the assignment to be atomic, where that abstraction may then do whatever is necessary on every architecture.</p>
<p>The other side effect of using atomic_t is that your variable becomes volatile, which may have an important effect on the compiled code.</p>
<p>So you gain abstracted atomicity and volatileness.  Are you still willing to say that this isn&#8217;t worthwhile?  Or is it just that this need is outside of what you consider &#8220;the vast majority of the time&#8221;?</p>
<p>PS &#8211; I hope you&#8217;ll excuse my pedantry for the sake of argument <img src='http://digitalvampire.org/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>
