Boost C++ Libraries: Ticket #10204: boost::lockfree:queue: g++ -fgnu-tm and -O1/2/3 flag not working https://svn.boost.org/trac10/ticket/10204 <p> The combination of g++ -fgnu-tm and optimization flags do not work when when using boost::lockfree::queue. </p> <pre class="wiki">#include &lt;boost/lockfree/queue.hpp&gt; int main () { boost::lockfree::queue&lt;int&gt; lfqueue; lfqueue.push(234); return 0; } </pre><p> Compiling it using </p> <pre class="wiki">g++ -std=c++11 -g -Wall -Werror -lboost_system -fgnu-tm </pre><p> works. Adding -O1 / -O2 / -O3 leads to the error: </p> <pre class="wiki">In file included from /usr/include/boost/atomic/detail/platform.hpp:22:0, from /usr/include/boost/atomic/atomic.hpp:17, from /usr/include/boost/atomic.hpp:12, from /usr/include/boost/lockfree/detail/atomic.hpp:39, from /usr/include/boost/lockfree/queue.hpp:22, from errtest.cpp:2: /usr/include/boost/atomic/detail/gcc-atomic.hpp: In member function ‘void boost::atomics::detail::base_atomic&lt;T, void, 8u, Sign&gt;::store(const value_type&amp;, boost::memory_order) volatile [with T = boost::lockfree::detail::tagged_ptr&lt;boost::lockfree::queue&lt;int&gt;::node&gt;; bool Sign = false; boost::atomics::detail::base_atomic&lt;T, void, 8u, Sign&gt;::value_type = boost::lockfree::detail::tagged_ptr&lt;boost::lockfree::queue&lt;int&gt;::node&gt;]’: /usr/include/boost/atomic/detail/gcc-atomic.hpp:35:39: error: inlining failed in call to always_inline ‘constexpr int boost::atomics::detail::convert_memory_order_to_gcc(boost::memory_order) noexcept’: BOOST_FORCEINLINE BOOST_CONSTEXPR int convert_memory_order_to_gcc(memory_order order) BOOST_NOEXCEPT ^ In file included from /usr/include/boost/atomic/detail/platform.hpp:22:0, from /usr/include/boost/atomic/atomic.hpp:17, from /usr/include/boost/atomic.hpp:12, from /usr/include/boost/lockfree/detail/atomic.hpp:39, from /usr/include/boost/lockfree/queue.hpp:22, from errtest.cpp:2: /usr/include/boost/atomic/detail/gcc-atomic.hpp:764:87: error: called from here __atomic_store_n(&amp;v_, tmp, atomics::detail::convert_memory_order_to_gcc(order)); </pre><p> I am using an up-to-date arch linux system with gcc 4.9.0 and boost 1.55.0 </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/10204 Trac 1.4.3 timblechmann Wed, 16 Jul 2014 12:44:53 GMT component changed https://svn.boost.org/trac10/ticket/10204#comment:1 https://svn.boost.org/trac10/ticket/10204#comment:1 <ul> <li><strong>component</strong> <span class="trac-field-old">lockfree</span> → <span class="trac-field-new">atomic</span> </li> </ul> <p> seem to be related to boost.atomic, which was pretty much rewritten for 1.56. can you test one of the beta releases? </p> Ticket anonymous Wed, 16 Jul 2014 15:21:25 GMT <link>https://svn.boost.org/trac10/ticket/10204#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10204#comment:2</guid> <description> <p> With boost 1.56 I get the same error (it only uses different header files): </p> <pre class="wiki">g++ -Idownload/modular-boost/ -O2 -fgnu-tm errtest.cpp In file included from download/modular-boost/boost/atomic/detail/operations_lockfree.hpp:21:0, from download/modular-boost/boost/atomic/detail/operations.hpp:17, from download/modular-boost/boost/atomic/fences.hpp:21, from download/modular-boost/boost/atomic/atomic.hpp:20, from download/modular-boost/boost/atomic.hpp:12, from download/modular-boost/boost/lockfree/detail/atomic.hpp:30, from download/modular-boost/boost/lockfree/queue.hpp:19, from errtest.cpp:1: download/modular-boost/boost/atomic/detail/ops_gcc_atomic.hpp: In static member function ‘static v download/modular-boost/boost/atomic/detail/ops_gcc_atomic.hpp:67:39: error: inlining failed in cal BOOST_FORCEINLINE BOOST_CONSTEXPR int convert_memory_order_to_gcc(memory_order order) BOOST_NOEXC ^ download/modular-boost/boost/atomic/detail/ops_gcc_atomic.hpp:81:90: error: called from here __atomic_store_n(&amp;storage, v, atomics::detail::convert_memory_order_to_gcc(order)); </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>olli</dc:creator> <pubDate>Fri, 01 Aug 2014 07:05:48 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10204#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10204#comment:3</guid> <description> <p> replace BOOST_FORCEINLINE by inline (in file boost/atomic/detail/gcc-atomic.hpp, line 35) -&gt; code compiles </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Andrey Semashev</dc:creator> <pubDate>Fri, 01 Aug 2014 08:44:37 GMT</pubDate> <title>cc set https://svn.boost.org/trac10/ticket/10204#comment:4 https://svn.boost.org/trac10/ticket/10204#comment:4 <ul> <li><strong>cc</strong> <span class="trac-author">Andrey.Semashev@…</span> added </li> </ul> <p> I cannot reproduce this with gcc 4.8.2 but it shows with 4.7.3. </p> <p> BOOST_FORCEINLINE is crucial in Boost.Atomic, it cannot be replaced with inline lightly. For now I don't have a solution for this, so I'm afraid at least 1.56 will be released with this problem. </p> Ticket Andrey Semashev Fri, 01 Aug 2014 08:56:21 GMT <link>https://svn.boost.org/trac10/ticket/10204#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10204#comment:5</guid> <description> <p> BTW, this gcc bug seems to be related: <a class="ext-link" href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53991"><span class="icon">​</span>https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53991</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>olli</dc:creator> <pubDate>Fri, 01 Aug 2014 10:08:50 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10204#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10204#comment:6</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/10204#comment:4" title="Comment 4">andysem</a>: </p> <blockquote class="citation"> <p> I cannot reproduce this with gcc 4.8.2 but it shows with 4.7.3. </p> </blockquote> <p> I can reproduce the error with gcc 4.8.2 - using <code>boost::atomic&lt;&gt;</code> and <code>__transaction_atomic</code> in the same app </p> <blockquote class="citation"> <p> BOOST_FORCEINLINE is crucial in Boost.Atomic, it cannot be replaced with inline lightly. </p> </blockquote> <p> could you explain it why it is crucial, please </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Andrey Semashev</dc:creator> <pubDate>Fri, 01 Aug 2014 10:16:24 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10204#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10204#comment:7</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/10204#comment:6" title="Comment 6">olli</a>: </p> <blockquote class="citation"> <p> I can reproduce the error with gcc 4.8.2 - using <code>boost::atomic&lt;&gt;</code> and <code>__transaction_atomic</code> in the same app </p> </blockquote> <p> I don't have experience with gcc transactions, but as far as I understand atomic ops are not transaction safe and therefore should not be used inside transactions. </p> <blockquote class="citation"> <blockquote class="citation"> <p> BOOST_FORCEINLINE is crucial in Boost.Atomic, it cannot be replaced with inline lightly. </p> </blockquote> <p> could you explain it why it is crucial, please </p> </blockquote> <p> It is commented in boost/atomic/detail/ops_gcc_atomic.hpp. In short, atomic&lt;&gt; functions must be inlined so that the compiler is able to see memory order arguments as constants. Otherwise it behaves as if seq_cst was specified. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>olli</dc:creator> <pubDate>Fri, 01 Aug 2014 10:48:54 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10204#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10204#comment:8</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/10204#comment:7" title="Comment 7">andysem</a>: </p> <blockquote class="citation"> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/10204#comment:6" title="Comment 6">olli</a>: </p> <blockquote class="citation"> <p> I can reproduce the error with gcc 4.8.2 - using <code>boost::atomic&lt;&gt;</code> and <code>__transaction_atomic</code> in the same app </p> </blockquote> <p> I don't have experience with gcc transactions, but as far as I understand atomic ops are not transaction safe and therefore should not be used inside transactions. </p> </blockquote> <p> I do not use atomics inside <code>__transaction_atomic</code> - only some parts of the code using atomics (e.g. spinlocks) are replaced by <code>__transaction_atomic</code> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Andrey Semashev</dc:creator> <pubDate>Wed, 14 Sep 2016 19:33:16 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/10204#comment:9 https://svn.boost.org/trac10/ticket/10204#comment:9 <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> I don't think we will be able to work around this. </p> Ticket