Boost C++ Libraries: Ticket #7892: boost.atomic misbehaves with Apple clang version 4.1 and -O2 https://svn.boost.org/trac10/ticket/7892 <p> There seems to be an issue, when assigning to an atomic in a "while (true)" loop (without break statement!). </p> <pre class="wiki">#include &lt;boost/atomic.hpp&gt; void this_works() { boost::atomic_bool b(false); std::cout &lt;&lt; b &lt;&lt; std::endl; // 0 b = true; std::cout &lt;&lt; b &lt;&lt; std::endl; // 1 } void this_works_too() { boost::atomic_bool b(false); while (true) { std::cout &lt;&lt; b &lt;&lt; std::endl; // 0 b = true; std::cout &lt;&lt; b &lt;&lt; std::endl; // 1 break; } } void this_doesnt_work() { boost::atomic_bool b(false); while (true) { std::cout &lt;&lt; b &lt;&lt; std::endl; // 0 b = true; std::cout &lt;&lt; b &lt;&lt; std::endl; // 0 } } // Issue arises when compiled with Apple LLVM 4.1 and -O2: // clang++ -O2 main.cpp int main(int argc, char ** argv) { this_works(); this_works_too(); this_doesnt_work(); return 0; } </pre><p> This happens only when the optimization level is set to at least 2. It happens in clang++ 4.1, but works in clang++ 3.2. Maybe it's possible to work around that issue, since std::atomic works fine. </p> <p> Best regards, Andreas </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7892 Trac 1.4.3 timblechmann Mon, 14 Jan 2013 21:46:39 GMT <link>https://svn.boost.org/trac10/ticket/7892#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7892#comment:1</guid> <description> <p> being a compiler bug, i'd strongly suggest to file a bug report at your compiler vendor, not at the library that triggers the bug. </p> </description> <category>Ticket</category> </item> <item> <author>Andreas Beisler <ebfx@…></author> <pubDate>Mon, 14 Jan 2013 22:34:54 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7892#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7892#comment:2</guid> <description> <p> Yes, that makes sense, but I was still hoping that there might be a fix to make it work with clang++ 4.1 before boost.atomic is officially released. After all, this version of clang++ is the standard compiler in Xcode for a while now... I will file a bug report at the compiler vendor, too. Thanks. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>timblechmann</dc:creator> <pubDate>Tue, 15 Jan 2013 08:59:24 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7892#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7892#comment:3</guid> <description> <p> fyi, mentioning this issue at the #llvm irc, the reply was: if clang-3.2 works, it appears to be fixed ... </p> <p> no idea of their policy of backporting fixes to releases ... one might work around the issue by doing a completely different implementation of atomic for clang, using compiler intrinsics instead of inline assembly ... </p> </description> <category>Ticket</category> </item> <item> <author>Andreas Beisler <ebfx@…></author> <pubDate>Tue, 15 Jan 2013 09:47:41 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7892#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7892#comment:4</guid> <description> <p> Ah, my bad. I tested <span class="underline">Apple</span> clang 4.1 (which is based on clang 3.1) and someone in the #boost irc channel replied that it was working in 'clang 3.2'. I thought he was talking about Apple clang 3.2 and that it was a regression. </p> <p> So, slight mix-up with the versions on my side. It's all good then. </p> <p> Thanks for your time! </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 15 Jan 2013 09:57:47 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7892#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7892#comment:5</guid> <description> <p> 'apple clang' != 'clang' ... both have different version numbers ... </p> </description> <category>Ticket</category> </item> <item> <dc:creator>timblechmann</dc:creator> <pubDate>Sun, 03 Mar 2013 11:52:31 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/7892#comment:6 https://svn.boost.org/trac10/ticket/7892#comment:6 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">wontfix</span> </li> </ul> <p> closing it as wontfix. if someone provides a patch to work around this compiler bug, please reopen. </p> Ticket