<?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: pthread mutex vs pthread spinlock</title>
	<atom:link href="http://www.alexonlinux.com/pthread-mutex-vs-pthread-spinlock/feed" rel="self" type="application/rss+xml" />
	<link>http://www.alexonlinux.com/pthread-mutex-vs-pthread-spinlock</link>
	<description></description>
	<lastBuildDate>Sun, 05 Feb 2012 21:17:46 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
	<item>
		<title>By: Alexander Sandler</title>
		<link>http://www.alexonlinux.com/pthread-mutex-vs-pthread-spinlock/comment-page-1#comment-28438</link>
		<dc:creator>Alexander Sandler</dc:creator>
		<pubDate>Sun, 05 Feb 2012 21:07:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.alexonlinux.com/?p=1303#comment-28438</guid>
		<description>&lt;a href=&#039;#comment-27815&#039; rel=&quot;nofollow&quot;&gt;@Juan Bolsa&lt;/a&gt;
Well, it is not exactly better. It is different. Use it carefully.&lt;div class=&quot;comment-remix-meta&quot;&gt;&lt;a href=&quot;#&quot; class=&quot;replyto&quot; onclick=&quot;replyto(&#039;28438&#039;,&#039;Alexander Sandler&#039;); return false;&quot;&gt;Reply&lt;/a&gt;  - &lt;a href=&quot;#&quot; class=&quot;quote&quot; onclick=&quot;quote(&#039;28438&#039;,&#039;Alexander Sandler&#039;,&#039;&lt;a href=\&#039;#comment-27815\&#039; rel=\&quot;nofollow\&quot;&gt;@Juan Bolsa&lt;\/a&gt;\r\nWell, it is not exactly better. It is different. Use it carefully.&#039;); return false;&quot;&gt;Quote&lt;/a&gt;&lt;/div&gt;</description>
		<content:encoded><![CDATA[<p><a href="#comment-27815' rel="nofollow">@Juan Bolsa</a><br />
Well, it is not exactly better. It is different. Use it carefully.
<div class="comment-remix-meta"><a href="#" class="replyto" onclick="replyto('28438','Alexander Sandler'); return false;">Reply</a>  &#8211; <a href="#" class="quote" onclick="quote('28438','Alexander Sandler','&lt;a href=\'#comment-27815\' rel=\&quot;nofollow\&quot;&gt;@Juan Bolsa&lt;\/a&gt;\r\nWell, it is not exactly better. It is different. Use it carefully.'); return false;">Quote</a></div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Juan Bolsa</title>
		<link>http://www.alexonlinux.com/pthread-mutex-vs-pthread-spinlock/comment-page-1#comment-27815</link>
		<dc:creator>Juan Bolsa</dc:creator>
		<pubDate>Mon, 28 Nov 2011 20:41:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.alexonlinux.com/?p=1303#comment-27815</guid>
		<description>I didn&#039;t know the real functions of the spinlock, this much better than a mutex.Thanks for sharing&lt;div class=&quot;comment-remix-meta&quot;&gt;&lt;a href=&quot;#&quot; class=&quot;replyto&quot; onclick=&quot;replyto(&#039;27815&#039;,&#039;Juan Bolsa&#039;); return false;&quot;&gt;Reply&lt;/a&gt;  - &lt;a href=&quot;#&quot; class=&quot;quote&quot; onclick=&quot;quote(&#039;27815&#039;,&#039;Juan Bolsa&#039;,&#039;I didn\&#039;t know the real functions of the spinlock, this much better than a mutex.Thanks for sharing&#039;); return false;&quot;&gt;Quote&lt;/a&gt;&lt;/div&gt;</description>
		<content:encoded><![CDATA[<p>I didn&#8217;t know the real functions of the spinlock, this much better than a mutex.Thanks for sharing
<div class="comment-remix-meta"><a href="#" class="replyto" onclick="replyto('27815','Juan Bolsa'); return false;">Reply</a>  &#8211; <a href="#" class="quote" onclick="quote('27815','Juan Bolsa','I didn\'t know the real functions of the spinlock, this much better than a mutex.Thanks for sharing'); return false;">Quote</a></div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Multi-threaded programming: efficiency of locking &#171; Attractive Chaos</title>
		<link>http://www.alexonlinux.com/pthread-mutex-vs-pthread-spinlock/comment-page-1#comment-27420</link>
		<dc:creator>Multi-threaded programming: efficiency of locking &#171; Attractive Chaos</dc:creator>
		<pubDate>Thu, 06 Oct 2011 15:01:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.alexonlinux.com/?p=1303#comment-27420</guid>
		<description>[...] explore both spinlock and mutex. Although using mutex is usually safer and more portable, spinlock may be faster (careless micro-benchmarks tend to prefer spinlock actually). Nonetheless, let me emphasize again [...]&lt;div class=&quot;comment-remix-meta&quot;&gt;&lt;a href=&quot;#&quot; class=&quot;replyto&quot; onclick=&quot;replyto(&#039;27420&#039;,&#039;Multi-threaded programming: efficiency of locking &laquo; Attractive Chaos&#039;); return false;&quot;&gt;Reply&lt;/a&gt;  - &lt;a href=&quot;#&quot; class=&quot;quote&quot; onclick=&quot;quote(&#039;27420&#039;,&#039;Multi-threaded programming: efficiency of locking &laquo; Attractive Chaos&#039;,&#039;&#091;...&#093; explore both spinlock and mutex. Although using mutex is usually safer and more portable, spinlock may be faster (careless micro-benchmarks tend to prefer spinlock actually). Nonetheless, let me emphasize again &#091;...&#093;&#039;); return false;&quot;&gt;Quote&lt;/a&gt;&lt;/div&gt;</description>
		<content:encoded><![CDATA[<p>[...] explore both spinlock and mutex. Although using mutex is usually safer and more portable, spinlock may be faster (careless micro-benchmarks tend to prefer spinlock actually). Nonetheless, let me emphasize again [...]
<div class="comment-remix-meta"><a href="#" class="replyto" onclick="replyto('27420','Multi-threaded programming: efficiency of locking &amp;laquo; Attractive Chaos'); return false;">Reply</a>  &#8211; <a href="#" class="quote" onclick="quote('27420','Multi-threaded programming: efficiency of locking &amp;laquo; Attractive Chaos','&amp;#91;...&amp;#93; explore both spinlock and mutex. Although using mutex is usually safer and more portable, spinlock may be faster (careless micro-benchmarks tend to prefer spinlock actually). Nonetheless, let me emphasize again &amp;#91;...&amp;#93;'); return false;">Quote</a></div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alexander Sandler</title>
		<link>http://www.alexonlinux.com/pthread-mutex-vs-pthread-spinlock/comment-page-1#comment-27171</link>
		<dc:creator>Alexander Sandler</dc:creator>
		<pubDate>Sun, 18 Sep 2011 08:34:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.alexonlinux.com/?p=1303#comment-27171</guid>
		<description>&lt;a href=&#039;#comment-27046&#039; rel=&quot;nofollow&quot;&gt;@JT&lt;/a&gt;
Thanks for backing me up and you are absolutely right.&lt;div class=&quot;comment-remix-meta&quot;&gt;&lt;a href=&quot;#&quot; class=&quot;replyto&quot; onclick=&quot;replyto(&#039;27171&#039;,&#039;Alexander Sandler&#039;); return false;&quot;&gt;Reply&lt;/a&gt;  - &lt;a href=&quot;#&quot; class=&quot;quote&quot; onclick=&quot;quote(&#039;27171&#039;,&#039;Alexander Sandler&#039;,&#039;&lt;a href=\&#039;#comment-27046\&#039; rel=\&quot;nofollow\&quot;&gt;@JT&lt;\/a&gt;\r\nThanks for backing me up and you are absolutely right.&#039;); return false;&quot;&gt;Quote&lt;/a&gt;&lt;/div&gt;</description>
		<content:encoded><![CDATA[<p><a href="#comment-27046' rel="nofollow">@JT</a><br />
Thanks for backing me up and you are absolutely right.
<div class="comment-remix-meta"><a href="#" class="replyto" onclick="replyto('27171','Alexander Sandler'); return false;">Reply</a>  &#8211; <a href="#" class="quote" onclick="quote('27171','Alexander Sandler','&lt;a href=\'#comment-27046\' rel=\&quot;nofollow\&quot;&gt;@JT&lt;\/a&gt;\r\nThanks for backing me up and you are absolutely right.'); return false;">Quote</a></div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alexander Sandler</title>
		<link>http://www.alexonlinux.com/pthread-mutex-vs-pthread-spinlock/comment-page-1#comment-27170</link>
		<dc:creator>Alexander Sandler</dc:creator>
		<pubDate>Sun, 18 Sep 2011 08:18:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.alexonlinux.com/?p=1303#comment-27170</guid>
		<description>&lt;a href=&#039;#comment-26481&#039; rel=&quot;nofollow&quot;&gt;@Erik&lt;/a&gt;
My pleasure. Please come again :-)&lt;div class=&quot;comment-remix-meta&quot;&gt;&lt;a href=&quot;#&quot; class=&quot;replyto&quot; onclick=&quot;replyto(&#039;27170&#039;,&#039;Alexander Sandler&#039;); return false;&quot;&gt;Reply&lt;/a&gt;  - &lt;a href=&quot;#&quot; class=&quot;quote&quot; onclick=&quot;quote(&#039;27170&#039;,&#039;Alexander Sandler&#039;,&#039;&lt;a href=\&#039;#comment-26481\&#039; rel=\&quot;nofollow\&quot;&gt;@Erik&lt;\/a&gt;\r\nMy pleasure. Please come again :-)&#039;); return false;&quot;&gt;Quote&lt;/a&gt;&lt;/div&gt;</description>
		<content:encoded><![CDATA[<p><a href="#comment-26481' rel="nofollow">@Erik</a><br />
My pleasure. Please come again <img src='http://www.alexonlinux.com/wp-content/plugins/smilies-themer/modern/smile.gif' alt=':-)' class='wp-smiley' />
<div class="comment-remix-meta"><a href="#" class="replyto" onclick="replyto('27170','Alexander Sandler'); return false;">Reply</a>  &#8211; <a href="#" class="quote" onclick="quote('27170','Alexander Sandler','&lt;a href=\'#comment-26481\' rel=\&quot;nofollow\&quot;&gt;@Erik&lt;\/a&gt;\r\nMy pleasure. Please come again :-)'); return false;">Quote</a></div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alexander Sandler</title>
		<link>http://www.alexonlinux.com/pthread-mutex-vs-pthread-spinlock/comment-page-1#comment-27169</link>
		<dc:creator>Alexander Sandler</dc:creator>
		<pubDate>Sun, 18 Sep 2011 08:18:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.alexonlinux.com/?p=1303#comment-27169</guid>
		<description>&lt;a href=&#039;#comment-26028&#039; rel=&quot;nofollow&quot;&gt;@tr00per&lt;/a&gt;
I think we will have to analyze what -O3 optimization did in order to figure out why you got the numbers you got.&lt;div class=&quot;comment-remix-meta&quot;&gt;&lt;a href=&quot;#&quot; class=&quot;replyto&quot; onclick=&quot;replyto(&#039;27169&#039;,&#039;Alexander Sandler&#039;); return false;&quot;&gt;Reply&lt;/a&gt;  - &lt;a href=&quot;#&quot; class=&quot;quote&quot; onclick=&quot;quote(&#039;27169&#039;,&#039;Alexander Sandler&#039;,&#039;&lt;a href=\&#039;#comment-26028\&#039; rel=\&quot;nofollow\&quot;&gt;@tr00per&lt;\/a&gt;\r\nI think we will have to analyze what -O3 optimization did in order to figure out why you got the numbers you got.&#039;); return false;&quot;&gt;Quote&lt;/a&gt;&lt;/div&gt;</description>
		<content:encoded><![CDATA[<p><a href="#comment-26028' rel="nofollow">@tr00per</a><br />
I think we will have to analyze what -O3 optimization did in order to figure out why you got the numbers you got.
<div class="comment-remix-meta"><a href="#" class="replyto" onclick="replyto('27169','Alexander Sandler'); return false;">Reply</a>  &#8211; <a href="#" class="quote" onclick="quote('27169','Alexander Sandler','&lt;a href=\'#comment-26028\' rel=\&quot;nofollow\&quot;&gt;@tr00per&lt;\/a&gt;\r\nI think we will have to analyze what -O3 optimization did in order to figure out why you got the numbers you got.'); return false;">Quote</a></div>
]]></content:encoded>
	</item>
	<item>
		<title>By: JT</title>
		<link>http://www.alexonlinux.com/pthread-mutex-vs-pthread-spinlock/comment-page-1#comment-27046</link>
		<dc:creator>JT</dc:creator>
		<pubDate>Tue, 06 Sep 2011 20:33:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.alexonlinux.com/?p=1303#comment-27046</guid>
		<description>Hello,

Good article Alex.

A spinlock will be faster than a mutex.
A spinlock is a mechanism that gives a thread the ability to not get 
pre-empted (or blocked) by the kernel.
The side effect to this is that a thread that is waiting on a spinlock is more responsive, at the cost of cpu (since it will be spinning).
Since the thread is more responsive, it will execute it&#039;s instructions in less wall clock time.

A point to be noted is that a spinlock will not spin infinitely (the spin count is not documented), so in a worst case scenario a spinlock downgrades to a mutex.
Replacing all the mutex locks with spinlocks will only improve performance -
not degrade it.

Somebody wrongly noted that a spinlock will lead to &quot;priority inversion&quot; scenarios. This is not true.

The argument that spinlocks are useless on single processor machines, though
correct, should not be taken seriously since here are not many single
processor machines around anymore.

There are numerous cases where spinlocks are applicable.
A simple example is a message processor app.
eg: Thread(T1) reads from a socket and write to a queue(Q), Thread(T2) reads from the Q and does some processing. In this case the lock on the Q is very short lived and the threads T1, T2 have to be very responsive.


enjoy&lt;div class=&quot;comment-remix-meta&quot;&gt;&lt;a href=&quot;#&quot; class=&quot;replyto&quot; onclick=&quot;replyto(&#039;27046&#039;,&#039;JT&#039;); return false;&quot;&gt;Reply&lt;/a&gt;  - &lt;a href=&quot;#&quot; class=&quot;quote&quot; onclick=&quot;quote(&#039;27046&#039;,&#039;JT&#039;,&#039;Hello,\r\n\r\nGood article Alex.\r\n\r\nA spinlock will be faster than a mutex.\r\nA spinlock is a mechanism that gives a thread the ability to not get \r\npre-empted (or blocked) by the kernel.\r\nThe side effect to this is that a thread that is waiting on a spinlock is more responsive, at the cost of cpu (since it will be spinning).\r\nSince the thread is more responsive, it will execute it\&#039;s instructions in less wall clock time.\r\n\r\nA point to be noted is that a spinlock will not spin infinitely (the spin count is not documented), so in a worst case scenario a spinlock downgrades to a mutex.\r\nReplacing all the mutex locks with spinlocks will only improve performance -\r\nnot degrade it.\r\n\r\nSomebody wrongly noted that a spinlock will lead to \&quot;priority inversion\&quot; scenarios. This is not true.\r\n\r\nThe argument that spinlocks are useless on single processor machines, though\r\ncorrect, should not be taken seriously since here are not many single\r\nprocessor machines around anymore.\r\n\r\nThere are numerous cases where spinlocks are applicable.\r\nA simple example is a message processor app.\r\neg: Thread(T1) reads from a socket and write to a queue(Q), Thread(T2) reads from the Q and does some processing. In this case the lock on the Q is very short lived and the threads T1, T2 have to be very responsive.\r\n\r\n\r\nenjoy&#039;); return false;&quot;&gt;Quote&lt;/a&gt;&lt;/div&gt;</description>
		<content:encoded><![CDATA[<p>Hello,</p>
<p>Good article Alex.</p>
<p>A spinlock will be faster than a mutex.<br />
A spinlock is a mechanism that gives a thread the ability to not get<br />
pre-empted (or blocked) by the kernel.<br />
The side effect to this is that a thread that is waiting on a spinlock is more responsive, at the cost of cpu (since it will be spinning).<br />
Since the thread is more responsive, it will execute it&#8217;s instructions in less wall clock time.</p>
<p>A point to be noted is that a spinlock will not spin infinitely (the spin count is not documented), so in a worst case scenario a spinlock downgrades to a mutex.<br />
Replacing all the mutex locks with spinlocks will only improve performance -<br />
not degrade it.</p>
<p>Somebody wrongly noted that a spinlock will lead to &#8220;priority inversion&#8221; scenarios. This is not true.</p>
<p>The argument that spinlocks are useless on single processor machines, though<br />
correct, should not be taken seriously since here are not many single<br />
processor machines around anymore.</p>
<p>There are numerous cases where spinlocks are applicable.<br />
A simple example is a message processor app.<br />
eg: Thread(T1) reads from a socket and write to a queue(Q), Thread(T2) reads from the Q and does some processing. In this case the lock on the Q is very short lived and the threads T1, T2 have to be very responsive.</p>
<p>enjoy
<div class="comment-remix-meta"><a href="#" class="replyto" onclick="replyto('27046','JT'); return false;">Reply</a>  &#8211; <a href="#" class="quote" onclick="quote('27046','JT','Hello,\r\n\r\nGood article Alex.\r\n\r\nA spinlock will be faster than a mutex.\r\nA spinlock is a mechanism that gives a thread the ability to not get \r\npre-empted (or blocked) by the kernel.\r\nThe side effect to this is that a thread that is waiting on a spinlock is more responsive, at the cost of cpu (since it will be spinning).\r\nSince the thread is more responsive, it will execute it\'s instructions in less wall clock time.\r\n\r\nA point to be noted is that a spinlock will not spin infinitely (the spin count is not documented), so in a worst case scenario a spinlock downgrades to a mutex.\r\nReplacing all the mutex locks with spinlocks will only improve performance -\r\nnot degrade it.\r\n\r\nSomebody wrongly noted that a spinlock will lead to \&quot;priority inversion\&quot; scenarios. This is not true.\r\n\r\nThe argument that spinlocks are useless on single processor machines, though\r\ncorrect, should not be taken seriously since here are not many single\r\nprocessor machines around anymore.\r\n\r\nThere are numerous cases where spinlocks are applicable.\r\nA simple example is a message processor app.\r\neg: Thread(T1) reads from a socket and write to a queue(Q), Thread(T2) reads from the Q and does some processing. In this case the lock on the Q is very short lived and the threads T1, T2 have to be very responsive.\r\n\r\n\r\nenjoy'); return false;">Quote</a></div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Erik</title>
		<link>http://www.alexonlinux.com/pthread-mutex-vs-pthread-spinlock/comment-page-1#comment-26481</link>
		<dc:creator>Erik</dc:creator>
		<pubDate>Sun, 17 Jul 2011 02:54:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.alexonlinux.com/?p=1303#comment-26481</guid>
		<description>Thanks for the example! It compiled and worked great. Answered the exact question I&#039;ve been struggling with. Keep up the good work :-)&lt;div class=&quot;comment-remix-meta&quot;&gt;&lt;a href=&quot;#&quot; class=&quot;replyto&quot; onclick=&quot;replyto(&#039;26481&#039;,&#039;Erik&#039;); return false;&quot;&gt;Reply&lt;/a&gt;  - &lt;a href=&quot;#&quot; class=&quot;quote&quot; onclick=&quot;quote(&#039;26481&#039;,&#039;Erik&#039;,&#039;Thanks for the example! It compiled and worked great. Answered the exact question I\&#039;ve been struggling with. Keep up the good work :-)&#039;); return false;&quot;&gt;Quote&lt;/a&gt;&lt;/div&gt;</description>
		<content:encoded><![CDATA[<p>Thanks for the example! It compiled and worked great. Answered the exact question I&#8217;ve been struggling with. Keep up the good work <img src='http://www.alexonlinux.com/wp-content/plugins/smilies-themer/modern/smile.gif' alt=':-)' class='wp-smiley' />
<div class="comment-remix-meta"><a href="#" class="replyto" onclick="replyto('26481','Erik'); return false;">Reply</a>  &#8211; <a href="#" class="quote" onclick="quote('26481','Erik','Thanks for the example! It compiled and worked great. Answered the exact question I\'ve been struggling with. Keep up the good work :-)'); return false;">Quote</a></div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hasan</title>
		<link>http://www.alexonlinux.com/pthread-mutex-vs-pthread-spinlock/comment-page-1#comment-26218</link>
		<dc:creator>Hasan</dc:creator>
		<pubDate>Thu, 30 Jun 2011 07:31:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.alexonlinux.com/?p=1303#comment-26218</guid>
		<description>This gives a very good understanding of the Spin Lock versus the Mutex. after reading comments of others and my understanding that Spin lock should not be used in user mode in case of the uni-Processor system. But if the system is multicore, can they be beneficial in practical, i mean writing a fulfledge application. The example program clearly recommends that spin lock is a better bet in user mode as well. Though, I have not found anybody using Spinlock in user programs and they are best used in Kernel modules. what do you say?&lt;div class=&quot;comment-remix-meta&quot;&gt;&lt;a href=&quot;#&quot; class=&quot;replyto&quot; onclick=&quot;replyto(&#039;26218&#039;,&#039;Hasan&#039;); return false;&quot;&gt;Reply&lt;/a&gt;  - &lt;a href=&quot;#&quot; class=&quot;quote&quot; onclick=&quot;quote(&#039;26218&#039;,&#039;Hasan&#039;,&#039;This gives a very good understanding of the Spin Lock versus the Mutex. after reading comments of others and my understanding that Spin lock should not be used in user mode in case of the uni-Processor system. But if the system is multicore, can they be beneficial in practical, i mean writing a fulfledge application. The example program clearly recommends that spin lock is a better bet in user mode as well. Though, I have not found anybody using Spinlock in user programs and they are best used in Kernel modules. what do you say?&#039;); return false;&quot;&gt;Quote&lt;/a&gt;&lt;/div&gt;</description>
		<content:encoded><![CDATA[<p>This gives a very good understanding of the Spin Lock versus the Mutex. after reading comments of others and my understanding that Spin lock should not be used in user mode in case of the uni-Processor system. But if the system is multicore, can they be beneficial in practical, i mean writing a fulfledge application. The example program clearly recommends that spin lock is a better bet in user mode as well. Though, I have not found anybody using Spinlock in user programs and they are best used in Kernel modules. what do you say?
<div class="comment-remix-meta"><a href="#" class="replyto" onclick="replyto('26218','Hasan'); return false;">Reply</a>  &#8211; <a href="#" class="quote" onclick="quote('26218','Hasan','This gives a very good understanding of the Spin Lock versus the Mutex. after reading comments of others and my understanding that Spin lock should not be used in user mode in case of the uni-Processor system. But if the system is multicore, can they be beneficial in practical, i mean writing a fulfledge application. The example program clearly recommends that spin lock is a better bet in user mode as well. Though, I have not found anybody using Spinlock in user programs and they are best used in Kernel modules. what do you say?'); return false;">Quote</a></div>
]]></content:encoded>
	</item>
	<item>
		<title>By: tr00per</title>
		<link>http://www.alexonlinux.com/pthread-mutex-vs-pthread-spinlock/comment-page-1#comment-26028</link>
		<dc:creator>tr00per</dc:creator>
		<pubDate>Mon, 06 Jun 2011 17:56:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.alexonlinux.com/?p=1303#comment-26028</guid>
		<description>It seems argument invalidates if -O3 is given. Here are example runs on my machine:

$ g++ -o threadTest_spin -DUSE_SPINLOCK -lpthread threadTest.cpp
$ g++ -o threadTest_mutex -lpthread threadTest.cpp
$ ./threadTest_mutex
Thread test using mutex.
Consumer TID 6838
Consumer TID 6837
Result - 2.638293
$ ./threadTest_spin
Thread test using spin lock.
Consumer TID 6847
Consumer TID 6848
Result - 1.926722

$ g++ -o threadTest_spin -DUSE_SPINLOCK -O3 -lpthread threadTest.cpp
$ g++ -o threadTest_mutex -O3 -lpthread threadTest.cpp
$ ./threadTest_mutex
Thread test using mutex.
Consumer TID 6821
Consumer TID 6822
Result - 1.589208
$ ./threadTest_spin
Thread test using spin lock.
Consumer TID 6824
Consumer TID 6825
Result - 1.667864

2.6.38-ARCH x86_64 Intel(R) Core(TM)2 CPU 4400 @ 2.00GHz, g++ 4.6.0 20110513&lt;div class=&quot;comment-remix-meta&quot;&gt;&lt;a href=&quot;#&quot; class=&quot;replyto&quot; onclick=&quot;replyto(&#039;26028&#039;,&#039;tr00per&#039;); return false;&quot;&gt;Reply&lt;/a&gt;  - &lt;a href=&quot;#&quot; class=&quot;quote&quot; onclick=&quot;quote(&#039;26028&#039;,&#039;tr00per&#039;,&#039;It seems argument invalidates if -O3 is given. Here are example runs on my machine:\r\n\r\n$ g++ -o threadTest_spin -DUSE_SPINLOCK -lpthread threadTest.cpp\r\n$ g++ -o threadTest_mutex -lpthread threadTest.cpp\r\n$ .\/threadTest_mutex\r\nThread test using mutex.\r\nConsumer TID 6838\r\nConsumer TID 6837\r\nResult - 2.638293\r\n$ .\/threadTest_spin\r\nThread test using spin lock.\r\nConsumer TID 6847\r\nConsumer TID 6848\r\nResult - 1.926722\r\n\r\n$ g++ -o threadTest_spin -DUSE_SPINLOCK -O3 -lpthread threadTest.cpp\r\n$ g++ -o threadTest_mutex -O3 -lpthread threadTest.cpp\r\n$ .\/threadTest_mutex\r\nThread test using mutex.\r\nConsumer TID 6821\r\nConsumer TID 6822\r\nResult - 1.589208\r\n$ .\/threadTest_spin\r\nThread test using spin lock.\r\nConsumer TID 6824\r\nConsumer TID 6825\r\nResult - 1.667864\r\n\r\n2.6.38-ARCH x86_64 Intel(R) Core(TM)2 CPU 4400 @ 2.00GHz, g++ 4.6.0 20110513&#039;); return false;&quot;&gt;Quote&lt;/a&gt;&lt;/div&gt;</description>
		<content:encoded><![CDATA[<p>It seems argument invalidates if -O3 is given. Here are example runs on my machine:</p>
<p>$ g++ -o threadTest_spin -DUSE_SPINLOCK -lpthread threadTest.cpp<br />
$ g++ -o threadTest_mutex -lpthread threadTest.cpp<br />
$ ./threadTest_mutex<br />
Thread test using mutex.<br />
Consumer TID 6838<br />
Consumer TID 6837<br />
Result &#8211; 2.638293<br />
$ ./threadTest_spin<br />
Thread test using spin lock.<br />
Consumer TID 6847<br />
Consumer TID 6848<br />
Result &#8211; 1.926722</p>
<p>$ g++ -o threadTest_spin -DUSE_SPINLOCK -O3 -lpthread threadTest.cpp<br />
$ g++ -o threadTest_mutex -O3 -lpthread threadTest.cpp<br />
$ ./threadTest_mutex<br />
Thread test using mutex.<br />
Consumer TID 6821<br />
Consumer TID 6822<br />
Result &#8211; 1.589208<br />
$ ./threadTest_spin<br />
Thread test using spin lock.<br />
Consumer TID 6824<br />
Consumer TID 6825<br />
Result &#8211; 1.667864</p>
<p>2.6.38-ARCH x86_64 Intel(R) Core(TM)2 CPU 4400 @ 2.00GHz, g++ 4.6.0 20110513
<div class="comment-remix-meta"><a href="#" class="replyto" onclick="replyto('26028','tr00per'); return false;">Reply</a>  &#8211; <a href="#" class="quote" onclick="quote('26028','tr00per','It seems argument invalidates if -O3 is given. Here are example runs on my machine:\r\n\r\n$ g++ -o threadTest_spin -DUSE_SPINLOCK -lpthread threadTest.cpp\r\n$ g++ -o threadTest_mutex -lpthread threadTest.cpp\r\n$ .\/threadTest_mutex\r\nThread test using mutex.\r\nConsumer TID 6838\r\nConsumer TID 6837\r\nResult - 2.638293\r\n$ .\/threadTest_spin\r\nThread test using spin lock.\r\nConsumer TID 6847\r\nConsumer TID 6848\r\nResult - 1.926722\r\n\r\n$ g++ -o threadTest_spin -DUSE_SPINLOCK -O3 -lpthread threadTest.cpp\r\n$ g++ -o threadTest_mutex -O3 -lpthread threadTest.cpp\r\n$ .\/threadTest_mutex\r\nThread test using mutex.\r\nConsumer TID 6821\r\nConsumer TID 6822\r\nResult - 1.589208\r\n$ .\/threadTest_spin\r\nThread test using spin lock.\r\nConsumer TID 6824\r\nConsumer TID 6825\r\nResult - 1.667864\r\n\r\n2.6.38-ARCH x86_64 Intel(R) Core(TM)2 CPU 4400 @ 2.00GHz, g++ 4.6.0 20110513'); return false;">Quote</a></div>
]]></content:encoded>
	</item>
</channel>
</rss>

