Boost C++ Libraries: Ticket #6931: mutex waits forwever with Intel C++ Compiler XE 12.1.5.344 Build 20120612 https://svn.boost.org/trac10/ticket/6931 <p> The following in thread/win32/thread_primitives.hpp doesn't work with the latest Intel Compiler and the /debug:parallel option: </p> <blockquote> <p> inline bool interlocked_bit_test_and_set(long* x,long bit) { </p> <blockquote> <p> <span class="underline">asm { </span></p> <blockquote> <p> mov eax,bit; mov edx,x; lock bts [edx],eax; setc al; </p> </blockquote> <p> }; </p> </blockquote> <p> } </p> </blockquote> <blockquote> <p> inline bool interlocked_bit_test_and_reset(long* x,long bit) { </p> <blockquote> <p> <span class="underline">asm { </span></p> <blockquote> <p> mov eax,bit; mov edx,x; lock btr [edx],eax; setc al; </p> </blockquote> <p> }; </p> </blockquote> <p> } </p> </blockquote> <p> The Intel Compiler is immediately following the "setc al;" instructions with "mov eax, esp", trashing the return value. </p> <p> I'll report the problem to Intel, but I'm pretty sure that they will say that the behaviour the above code relies on isn't guaranteed by any compiler. </p> <p> The fix is simple: </p> <blockquote> <p> inline bool interlocked_bit_test_and_set(long* x,long bit) { </p> <blockquote> <p> bool ret; <span class="underline">asm { </span></p> <blockquote> <p> mov eax,bit; mov edx,x; lock bts [edx],eax; setc al; mov ret, al </p> </blockquote> <p> }; return ret; </p> </blockquote> <p> } </p> </blockquote> <blockquote> <p> inline bool interlocked_bit_test_and_reset(long* x,long bit) { </p> <blockquote> <p> bool ret; <span class="underline">asm { </span></p> <blockquote> <p> mov eax,bit; mov edx,x; lock btr [edx],eax; setc al; mov ret, al </p> </blockquote> </blockquote> <p> }; return ret; </p> </blockquote> <blockquote> <p> } </p> </blockquote> <p> Let the compiler optimize out the extra move should it so desire... </p> <p> Orin. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6931 Trac 1.4.3 viboes Mon, 28 May 2012 17:14:46 GMT component changed; owner set https://svn.boost.org/trac10/ticket/6931#comment:1 https://svn.boost.org/trac10/ticket/6931#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">Anthony Williams</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">thread</span> </li> </ul> Ticket viboes Thu, 05 Jul 2012 05:56:47 GMT owner, status changed https://svn.boost.org/trac10/ticket/6931#comment:2 https://svn.boost.org/trac10/ticket/6931#comment:2 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Anthony Williams</span> to <span class="trac-author">viboes</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket viboes Sat, 07 Jul 2012 15:12:40 GMT milestone changed https://svn.boost.org/trac10/ticket/6931#comment:3 https://svn.boost.org/trac10/ticket/6931#comment:3 <ul> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.51.0</span> </li> </ul> <p> Committed in trunk <a class="changeset" href="https://svn.boost.org/trac10/changeset/79337" title="Thread: changed assembler for interlocked_bit_test_and_set compatible hp">[79337]</a> </p> Ticket viboes Mon, 09 Jul 2012 21:13:18 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/6931#comment:4 https://svn.boost.org/trac10/ticket/6931#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Committed revision <a class="changeset" href="https://svn.boost.org/trac10/changeset/79373" title="Thread: merge from trunk">[79373]</a>. </p> Ticket abrarov@… Sun, 02 Sep 2012 06:36:08 GMT attachment set https://svn.boost.org/trac10/ticket/6931 https://svn.boost.org/trac10/ticket/6931 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">intel_12_1_mutex.patch</span> </li> </ul> <p> Patch for Intel C++ Compiler XE 12.1 and boost::mutex on Windows </p> Ticket abrarov@… Sun, 02 Sep 2012 06:47:56 GMT <link>https://svn.boost.org/trac10/ticket/6931#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6931#comment:5</guid> <description> <p> Hi, Orin and viboes. I have the same problem at my project (<a class="ext-link" href="http://sourceforge.net/projects/asio-samples"><span class="icon">​</span>http://sourceforge.net/projects/asio-samples</a>, project echo_server) with Intel C++ Compiler XE Version 12.1.5.344 Build 20120612, Boost C++ Libraries 1.51 and Windows 7 SP1 Pro. It seems (by means of disassembly view) that compiler optimizes asm block into something like: </p> <pre class="wiki">asm { mov edx, x; mov ret, edx; } </pre><p> The only solution that helps me is located at intel_12_1_mutex.patch (attached). </p> <p> Regards, Marat. </p> </description> <category>Ticket</category> </item> <item> <author>abrarov@…</author> <pubDate>Sun, 02 Sep 2012 06:53:19 GMT</pubDate> <title>status, summary, version, milestone changed; resolution deleted https://svn.boost.org/trac10/ticket/6931#comment:6 https://svn.boost.org/trac10/ticket/6931#comment:6 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>summary</strong> <span class="trac-field-old">mutex waits forwever with Intel Compiler and /debug:parallel</span> → <span class="trac-field-new">mutex waits forwever with Intel C++ Compiler XE 12.1.5.344 Build 20120612</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> <li><strong>version</strong> <span class="trac-field-old">Boost 1.49.0</span> → <span class="trac-field-new">Boost 1.51.0</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.51.0</span> → <span class="trac-field-new">To Be Determined</span> </li> </ul> Ticket viboes Sun, 02 Sep 2012 09:00:50 GMT <link>https://svn.boost.org/trac10/ticket/6931#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6931#comment:7</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/6931#comment:5" title="Comment 5">abrarov@…</a>: </p> <blockquote class="citation"> <p> Hi, Orin and viboes. I have the same problem at my project (<a class="ext-link" href="http://sourceforge.net/projects/asio-samples"><span class="icon">​</span>http://sourceforge.net/projects/asio-samples</a>, project echo_server) with Intel C++ Compiler XE Version 12.1.5.344 Build 20120612, Boost C++ Libraries 1.51 and Windows 7 SP1 Pro. It seems (by means of disassembly view) that compiler optimizes asm block into something like: </p> <pre class="wiki">asm { mov edx, x; mov ret, edx; } </pre><p> The only solution that helps me is located at intel_12_1_mutex.patch (attached). </p> <p> Regards, Marat. </p> </blockquote> <p> Orin please, let me know if this patch works for you. </p> </description> <category>Ticket</category> </item> <item> <author>abrarov@…</author> <pubDate>Sun, 02 Sep 2012 09:31:16 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6931#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6931#comment:8</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/6931#comment:7" title="Comment 7">viboes</a>: </p> <blockquote class="citation"> <p> Orin please, let me know if this patch works for you. </p> </blockquote> <p> Actually it is only a workaround that switches Intel compiler to use _interlockedbittestandset/_interlockedbittestandreset instead of inline asm. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 08 Sep 2012 21:05:02 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6931#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6931#comment:9</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/6931#comment:8" title="Comment 8">abrarov@…</a>: </p> <blockquote class="citation"> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/6931#comment:7" title="Comment 7">viboes</a>: </p> <blockquote class="citation"> <p> Orin please, let me know if this patch works for you. </p> </blockquote> <p> Actually it is only a workaround that switches Intel compiler to use _interlockedbittestandset/_interlockedbittestandreset instead of inline asm. </p> </blockquote> <p> Well if the assembler doesn't works and no body know how to fix it, I could consider this a fix, don't you? </p> </description> <category>Ticket</category> </item> <item> <author>abrarov@…</author> <pubDate>Sun, 09 Sep 2012 05:11:43 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6931#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6931#comment:10</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/6931#comment:9" title="Comment 9">viboes</a>: </p> <blockquote class="citation"> <p> Well if the assembler doesn't works and no body know how to fix it, I could consider this a fix, don't you? </p> </blockquote> <p> I consider it a compiler bug that can not be worked around with inline asm. Being the only solution for Boost to work correctly, it can be named "fix". </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 09 Sep 2012 19:32:12 GMT</pubDate> <title>milestone changed https://svn.boost.org/trac10/ticket/6931#comment:11 https://svn.boost.org/trac10/ticket/6931#comment:11 <ul> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.52.0</span> </li> </ul> <p> Patch applied on trunk. Committed in trunk posix part <a class="changeset" href="https://svn.boost.org/trac10/changeset/80449" title="Thread: start adding noexcept to recursive_mutex::try_lock. Uncomment ...">[80449]</a> </p> Ticket viboes Thu, 13 Sep 2012 19:18:39 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/6931#comment:12 https://svn.boost.org/trac10/ticket/6931#comment:12 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Committed revision 80516. </p> Ticket orine@… Tue, 18 Sep 2012 19:44:36 GMT <link>https://svn.boost.org/trac10/ticket/6931#comment:13 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6931#comment:13</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/6931#comment:7" title="Comment 7">viboes</a>: </p> <blockquote class="citation"> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/6931#comment:5" title="Comment 5">abrarov@…</a>: </p> <blockquote class="citation"> <p> Hi, Orin and viboes. I have the same problem at my project (<a class="ext-link" href="http://sourceforge.net/projects/asio-samples"><span class="icon">​</span>http://sourceforge.net/projects/asio-samples</a>, project echo_server) with Intel C++ Compiler XE Version 12.1.5.344 Build 20120612, Boost C++ Libraries 1.51 and Windows 7 SP1 Pro. It seems (by means of disassembly view) that compiler optimizes asm block into something like: </p> <pre class="wiki">asm { mov edx, x; mov ret, edx; } </pre><p> The only solution that helps me is located at intel_12_1_mutex.patch (attached). </p> <p> Regards, Marat. </p> </blockquote> <p> Orin please, let me know if this patch works for you. </p> </blockquote> <p> I was on vacation and didn't get chance. I would have agreed with it being a fix rather than a workaround given your experience. </p> <p> Orin. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>y.hoshizuki</dc:creator> <pubDate>Tue, 15 Jan 2013 10:42:53 GMT</pubDate> <title>status changed; resolution deleted https://svn.boost.org/trac10/ticket/6931#comment:14 https://svn.boost.org/trac10/ticket/6931#comment:14 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> </ul> <p> this patch (<a class="changeset" href="https://svn.boost.org/trac10/changeset/79337" title="Thread: changed assembler for interlocked_bit_test_and_set compatible hp">[79337]</a>) breaks mutex, using Intel Composer XE 2013. </p> <p> semicolon is the comment for MASM format. </p> <p> icl.exe compiles </p> <pre class="wiki">__asm { mov eax,bit; mov edx,x; lock bts [edx],eax; setc al; mov ret, al }; </pre><p> to </p> <pre class="wiki">; Begin ASM 00004 8b 45 0c mov eax, DWORD PTR [12+ebp] ;C:\boost-1.51.0\boost/thread/win32/thread_primitives.hpp:354.21 ; End ASM </pre><p> , and this code is meaningless. </p> Ticket y.hoshizuki Tue, 15 Jan 2013 13:24:48 GMT <link>https://svn.boost.org/trac10/ticket/6931#comment:15 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6931#comment:15</guid> <description> <p> this problem was already fixed by <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7272" title="#7272: Patches: win32/thread_primitives.hpp: (Unneccessary) Warning (closed: fixed)">#7272</a>. sorry. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Tue, 15 Jan 2013 17:26:09 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/6931#comment:16 https://svn.boost.org/trac10/ticket/6931#comment:16 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> Ticket