<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Lockfree_mpmc version 1.12 ... in Intel® Moderncode for Parallel Architectures</title>
    <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/Lockfree-mpmc-version-1-12/m-p/819433#M1225</link>
    <description>&lt;SPAN style="font-size: x-small;"&gt;&lt;P&gt;&lt;BR /&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;How to verify that lockfree_mpmc is correct ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can for example reason like this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;first , in the source code i am using a margin of &lt;/P&gt;&lt;P&gt;1000 threads, so you can not have more than 1000 threads &lt;/P&gt;&lt;P&gt;accessing the lockfree queue at the same time...&lt;/P&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: Times New Roman;"&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And here is the ObjectPascal source code of the push() side:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;---&lt;/P&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: x-small;"&gt;&lt;P&gt;function TLockfree_MPMC.push(tm : tNodeQueue):boolean;&lt;/P&gt;&lt;P&gt;var lasttail,newtemp:longword;&lt;/P&gt;&lt;P&gt;begin&lt;/P&gt;&lt;P&gt;if getlength &amp;gt;= fsize &lt;/P&gt;&lt;P&gt;then &lt;/P&gt;&lt;P&gt;begin&lt;/P&gt;&lt;P&gt;result:=false;&lt;/P&gt;&lt;P&gt;exit;&lt;/P&gt;&lt;P&gt;end; &lt;/P&gt;&lt;P&gt;result:=true;&lt;/P&gt;&lt;P&gt;newTemp:=LockedIncLong(temp);&lt;/P&gt;&lt;P&gt;lastTail:=newTemp-1;&lt;/P&gt;&lt;P&gt;setObject(lastTail,tm);&lt;/P&gt;&lt;P&gt;repeat&lt;/P&gt;&lt;P&gt;if CAS(tail,lasttail,newtemp) &lt;/P&gt;&lt;P&gt;then &lt;/P&gt;&lt;P&gt;begin&lt;/P&gt;&lt;P&gt;exit; &lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;asm pause end;&lt;/P&gt;&lt;P&gt;until false;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;----&lt;/P&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: Times New Roman;"&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, let say the size of the bounded lockfree_mpmc queue is 1000 , and &lt;/P&gt;&lt;P&gt;imagine that the threads are executing the "if getlength &amp;gt;= fsize " all at the same &lt;BR /&gt;time, and imagine that the getlength() returns 999, so, the &lt;BR /&gt;"if getlength &amp;gt;= fsize" will returns false , and since we have &lt;/P&gt;&lt;P&gt;fSize:=(1 shl aPower) - margin inside the constructor, &lt;/P&gt;&lt;P&gt;with a margin of 1000 (margin must be &amp;gt;= to the number of threads) , &lt;BR /&gt;there will be nooverflow. &lt;/P&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: x-small; font-family: Arial;"&gt;&lt;SPAN style="font-size: x-small; font-family: Arial;"&gt;&lt;P&gt;And here is the source code of the pop() side:&lt;/P&gt;&lt;P&gt;----&lt;/P&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: x-small;"&gt;&lt;P&gt;function TLockfree_MPMC.pop(var obj:tNodeQueue):boolean;&lt;/P&gt;&lt;P&gt;var lastHead : longword;&lt;/P&gt;&lt;P&gt;begin&lt;/P&gt;&lt;P&gt;repeat&lt;/P&gt;&lt;P&gt;lastHead:=head;&lt;/P&gt;&lt;P&gt;if tail&amp;lt;&amp;gt;head&lt;/P&gt;&lt;P&gt;then&lt;/P&gt;&lt;P&gt;begin&lt;/P&gt;&lt;P&gt;obj:=getObject(lastHead);&lt;/P&gt;&lt;P&gt;if CAS(head,lasthead,lasthead+1) &lt;/P&gt;&lt;P&gt;then &lt;/P&gt;&lt;P&gt;begin&lt;/P&gt;&lt;P&gt;result:=true;&lt;/P&gt;&lt;P&gt;exit;&lt;/P&gt;&lt;P&gt;end&lt;/P&gt;&lt;P&gt;else backoff2.delay;&lt;/P&gt;&lt;P&gt;end &lt;/P&gt;&lt;P&gt;else &lt;/P&gt;&lt;P&gt;begin&lt;/P&gt;&lt;P&gt;result:=false;&lt;/P&gt;&lt;P&gt;exit;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;until false;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: x-small; font-family: Arial;"&gt;&lt;SPAN style="font-size: x-small; font-family: Arial;"&gt;&lt;P&gt;----&lt;/P&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN style="font-family: Arial;"&gt;&lt;P&gt;As you have noticed, there is a test like this: &lt;/P&gt;&lt;P&gt;if CAS(head,lasthead,lasthead+1) , and this test &lt;/P&gt;&lt;P&gt;avoids something like the ABA problem, cause if head &lt;/P&gt;&lt;P&gt;have changed , the CAS() will fail.&lt;/P&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: x-small; font-family: Arial;"&gt;&lt;SPAN style="font-size: x-small; font-family: Arial;"&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Amine Moulay Ramdane&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/B&gt;</description>
    <pubDate>Sat, 19 May 2012 23:48:02 GMT</pubDate>
    <dc:creator>aminer10</dc:creator>
    <dc:date>2012-05-19T23:48:02Z</dc:date>
    <item>
      <title>Lockfree_mpmc version 1.12 ...</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/Lockfree-mpmc-version-1-12/m-p/819432#M1224</link>
      <description>&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Hello, &lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Look at: &lt;A href="http://www.emadar.com/fpc/lockfree.htm"&gt;http://www.emadar.com/fpc/lockfree.htm&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;BR /&gt;In the pop() side of this lockfree quueue we have: &lt;/P&gt;&lt;P&gt;-------------- &lt;BR /&gt;&lt;BR /&gt;function gFLQueue.pop(var tm:_R):boolean; &lt;BR /&gt;var newhead, lastHead : integer; &lt;BR /&gt;&lt;BR /&gt;begin &lt;BR /&gt;repeat &lt;BR /&gt;lastHead:=head; &lt;BR /&gt; if tail&amp;lt;&amp;gt;head &lt;BR /&gt; then &lt;BR /&gt; begin &lt;BR /&gt; pointer(newHead):=interlockedCompareExchange(pointer(head),pointer(lastHead &lt;BR /&gt; +1),pointer(lasthead)); &lt;BR /&gt;if newHead=lastHead &lt;BR /&gt; then &lt;BR /&gt; begin &lt;BR /&gt; tm:=getObject(lastHead); &lt;BR /&gt; result:=true; exit; &lt;BR /&gt;end; end &lt;BR /&gt;else &lt;BR /&gt;begin &lt;BR /&gt;result:=false; &lt;BR /&gt;exit; &lt;BR /&gt;end; &lt;BR /&gt;until false; &lt;BR /&gt;end; &lt;BR /&gt;end. &lt;BR /&gt;---- &lt;/P&gt;&lt;P&gt;If you have noticed, after he is incrementing head with an &lt;BR /&gt;interlockedCompareExchange(), he is doing a tm:=getObject(lastHead); &lt;BR /&gt;and this is an error i think, cause if the thread &lt;BR /&gt;is prempeted and another thread have put another value in the same &lt;BR /&gt;place as lashead, the value willl be invalid and corrupted. &lt;BR /&gt;I have corrected this problem in my lockfree_mpmc fifo queue version &lt;BR /&gt;1.12 &lt;BR /&gt;So, becarefull with those lockfree algorithms. &lt;/P&gt;&lt;P&gt;And i have tried to enhance my lockfree_mpmc and i have &lt;BR /&gt;used an exponential backoff in the pop side of the algorithm and it &lt;BR /&gt;gives better performance under contention with 28.317 millions pop transations &lt;BR /&gt;per second. &lt;/P&gt;&lt;P&gt;The queue with a windows critical section on both the push and the pop &lt;BR /&gt;sides of the algorithm scored very bad under contention with &lt;BR /&gt;4 threads. Here is the benchmarks using the windows critical section: &lt;/P&gt;&lt;P&gt;Only 370692 push transactions per second &lt;BR /&gt;and only 503024 push transactions per second &lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Now the list of memory ordering guarantees in the Intel x86 memory model: &lt;/P&gt;&lt;P&gt;Loads are not reordered with other loads. &lt;BR /&gt;Stores are not reordered with other stores. &lt;BR /&gt;Stores are not reordered with older loads. &lt;BR /&gt;In a multiprocessor system, memory ordering obeys causality (memory &lt;BR /&gt;ordering respects transitive visibility). &lt;BR /&gt;In a multiprocessor system, stores to the same location have a total &lt;BR /&gt;order. &lt;/P&gt;&lt;P&gt;In a multiprocessor system, locked instructions have a total order. &lt;BR /&gt;Loads and stores are not reordered with locked instructions. &lt;/P&gt;&lt;P&gt;But Loads may be reordered with older stores to different locations &lt;BR /&gt;But what is important for us is MEMORY VISIBILITY across threads.. &lt;/P&gt;&lt;P&gt;So, the only variables in lockfree_mpmc that are used across threads &lt;BR /&gt;are tail and head.. And since in a multiprocessor system, locked instructions &lt;BR /&gt;have a total order. So, the lock cmpxchg (inside the CAS) in the push() side &lt;BR /&gt;of lockfree_mpmc does in fact achieve sequential consistency and &lt;BR /&gt;LockedIncLong(temp) in the push side of lockfree_mpmc 1.12 also &lt;BR /&gt;achieve sequential consistency &lt;/P&gt;&lt;P&gt;And tail and head are properly aligned to avoid false sharing... &lt;/P&gt;&lt;P&gt;Andof course i was speaking about sequential consistency in the x86 architecture.. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;You candownload lockfree_mpmc 1.12 from:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://pages.videotron.com/aminer/"&gt;http://pages.videotron.com/aminer/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Amine Moulay Ramdane.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 19 May 2012 23:30:33 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/Lockfree-mpmc-version-1-12/m-p/819432#M1224</guid>
      <dc:creator>aminer10</dc:creator>
      <dc:date>2012-05-19T23:30:33Z</dc:date>
    </item>
    <item>
      <title>Lockfree_mpmc version 1.12 ...</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/Lockfree-mpmc-version-1-12/m-p/819433#M1225</link>
      <description>&lt;SPAN style="font-size: x-small;"&gt;&lt;P&gt;&lt;BR /&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;How to verify that lockfree_mpmc is correct ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can for example reason like this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;first , in the source code i am using a margin of &lt;/P&gt;&lt;P&gt;1000 threads, so you can not have more than 1000 threads &lt;/P&gt;&lt;P&gt;accessing the lockfree queue at the same time...&lt;/P&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: Times New Roman;"&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And here is the ObjectPascal source code of the push() side:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;---&lt;/P&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: x-small;"&gt;&lt;P&gt;function TLockfree_MPMC.push(tm : tNodeQueue):boolean;&lt;/P&gt;&lt;P&gt;var lasttail,newtemp:longword;&lt;/P&gt;&lt;P&gt;begin&lt;/P&gt;&lt;P&gt;if getlength &amp;gt;= fsize &lt;/P&gt;&lt;P&gt;then &lt;/P&gt;&lt;P&gt;begin&lt;/P&gt;&lt;P&gt;result:=false;&lt;/P&gt;&lt;P&gt;exit;&lt;/P&gt;&lt;P&gt;end; &lt;/P&gt;&lt;P&gt;result:=true;&lt;/P&gt;&lt;P&gt;newTemp:=LockedIncLong(temp);&lt;/P&gt;&lt;P&gt;lastTail:=newTemp-1;&lt;/P&gt;&lt;P&gt;setObject(lastTail,tm);&lt;/P&gt;&lt;P&gt;repeat&lt;/P&gt;&lt;P&gt;if CAS(tail,lasttail,newtemp) &lt;/P&gt;&lt;P&gt;then &lt;/P&gt;&lt;P&gt;begin&lt;/P&gt;&lt;P&gt;exit; &lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;asm pause end;&lt;/P&gt;&lt;P&gt;until false;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;----&lt;/P&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: Times New Roman;"&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, let say the size of the bounded lockfree_mpmc queue is 1000 , and &lt;/P&gt;&lt;P&gt;imagine that the threads are executing the "if getlength &amp;gt;= fsize " all at the same &lt;BR /&gt;time, and imagine that the getlength() returns 999, so, the &lt;BR /&gt;"if getlength &amp;gt;= fsize" will returns false , and since we have &lt;/P&gt;&lt;P&gt;fSize:=(1 shl aPower) - margin inside the constructor, &lt;/P&gt;&lt;P&gt;with a margin of 1000 (margin must be &amp;gt;= to the number of threads) , &lt;BR /&gt;there will be nooverflow. &lt;/P&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: x-small; font-family: Arial;"&gt;&lt;SPAN style="font-size: x-small; font-family: Arial;"&gt;&lt;P&gt;And here is the source code of the pop() side:&lt;/P&gt;&lt;P&gt;----&lt;/P&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: x-small;"&gt;&lt;P&gt;function TLockfree_MPMC.pop(var obj:tNodeQueue):boolean;&lt;/P&gt;&lt;P&gt;var lastHead : longword;&lt;/P&gt;&lt;P&gt;begin&lt;/P&gt;&lt;P&gt;repeat&lt;/P&gt;&lt;P&gt;lastHead:=head;&lt;/P&gt;&lt;P&gt;if tail&amp;lt;&amp;gt;head&lt;/P&gt;&lt;P&gt;then&lt;/P&gt;&lt;P&gt;begin&lt;/P&gt;&lt;P&gt;obj:=getObject(lastHead);&lt;/P&gt;&lt;P&gt;if CAS(head,lasthead,lasthead+1) &lt;/P&gt;&lt;P&gt;then &lt;/P&gt;&lt;P&gt;begin&lt;/P&gt;&lt;P&gt;result:=true;&lt;/P&gt;&lt;P&gt;exit;&lt;/P&gt;&lt;P&gt;end&lt;/P&gt;&lt;P&gt;else backoff2.delay;&lt;/P&gt;&lt;P&gt;end &lt;/P&gt;&lt;P&gt;else &lt;/P&gt;&lt;P&gt;begin&lt;/P&gt;&lt;P&gt;result:=false;&lt;/P&gt;&lt;P&gt;exit;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;until false;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: x-small; font-family: Arial;"&gt;&lt;SPAN style="font-size: x-small; font-family: Arial;"&gt;&lt;P&gt;----&lt;/P&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN style="font-family: Arial;"&gt;&lt;P&gt;As you have noticed, there is a test like this: &lt;/P&gt;&lt;P&gt;if CAS(head,lasthead,lasthead+1) , and this test &lt;/P&gt;&lt;P&gt;avoids something like the ABA problem, cause if head &lt;/P&gt;&lt;P&gt;have changed , the CAS() will fail.&lt;/P&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: x-small; font-family: Arial;"&gt;&lt;SPAN style="font-size: x-small; font-family: Arial;"&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Amine Moulay Ramdane&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/B&gt;</description>
      <pubDate>Sat, 19 May 2012 23:48:02 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/Lockfree-mpmc-version-1-12/m-p/819433#M1225</guid>
      <dc:creator>aminer10</dc:creator>
      <dc:date>2012-05-19T23:48:02Z</dc:date>
    </item>
    <item>
      <title>Lockfree_mpmc version 1.12 ...</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/Lockfree-mpmc-version-1-12/m-p/819434#M1226</link>
      <description>&lt;P&gt;Microsoft Office 2010 is actually the newest software from microsoft office 2010 keys Microsoft Corporation introduced in the last year. Its leading aims tend to be to catch the present business requirements and to be on top of every competition with regard to the international market criteria. This can be a very good idea to obtain Microsoft Office 2010 Key immediately to maintain norton antivirus keys yourself up-to-date and to present you with the vast qualified progress opportunities for success. Microsoft Office 2010 is available in both 32-bit and 64-bit editions, but attention please the two are not able to co-exist on the very same personal computer. All of the Office 2010 editions are kaspersky antivirus keys suitable for Windows XP SP3, Windows Vista and Windows 7.&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.intel.com/www.keyyeah.com" target="_blank"&gt;www.keyyeah.com&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 28 May 2012 08:12:09 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/Lockfree-mpmc-version-1-12/m-p/819434#M1226</guid>
      <dc:creator>tomorrowwillbefine</dc:creator>
      <dc:date>2012-05-28T08:12:09Z</dc:date>
    </item>
  </channel>
</rss>

