Opened 8 years ago

Closed 6 years ago

#10204 closed Bugs (wontfix)

boost::lockfree:queue: g++ -fgnu-tm and -O1/2/3 flag not working

Reported by: philipp.schoppe@… Owned by: timblechmann
Milestone: To Be Determined Component: atomic
Version: Boost 1.55.0 Severity: Problem
Keywords: -fgnu-tm -O compiler flag combination Cc: Andrey.Semashev@…

Description

The combination of g++ -fgnu-tm and optimization flags do not work when when using boost::lockfree::queue.

#include <boost/lockfree/queue.hpp> 

int main () { 

     boost::lockfree::queue<int> lfqueue; 
     lfqueue.push(234); 

     return 0; 
} 

Compiling it using

g++ -std=c++11 -g -Wall -Werror -lboost_system -fgnu-tm

works. Adding -O1 / -O2 / -O3 leads to the error:

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<T, void, 8u, Sign>::store(const value_type&, boost::memory_order) volatile [with T = boost::lockfree::detail::tagged_ptr<boost::lockfree::queue<int>::node>; bool Sign = false; boost::atomics::detail::base_atomic<T, void, 8u, Sign>::value_type = boost::lockfree::detail::tagged_ptr<boost::lockfree::queue<int>::node>]’:
/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(&v_, tmp, atomics::detail::convert_memory_order_to_gcc(order));

I am using an up-to-date arch linux system with gcc 4.9.0 and boost 1.55.0

Change History (9)

comment:1 by timblechmann, 8 years ago

Component: lockfreeatomic

seem to be related to boost.atomic, which was pretty much rewritten for 1.56. can you test one of the beta releases?

comment:2 by anonymous, 8 years ago

With boost 1.56 I get the same error (it only uses different header files):

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(&storage, v, atomics::detail::convert_memory_order_to_gcc(order));

comment:3 by olli, 8 years ago

replace BOOST_FORCEINLINE by inline (in file boost/atomic/detail/gcc-atomic.hpp, line 35) -> code compiles

comment:4 by Andrey Semashev, 8 years ago

Cc: Andrey.Semashev@… added

I cannot reproduce this with gcc 4.8.2 but it shows with 4.7.3.

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.

comment:5 by Andrey Semashev, 8 years ago

BTW, this gcc bug seems to be related: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53991

in reply to:  4 ; comment:6 by olli, 8 years ago

Replying to andysem:

I cannot reproduce this with gcc 4.8.2 but it shows with 4.7.3.

I can reproduce the error with gcc 4.8.2 - using boost::atomic<> and __transaction_atomic in the same app

BOOST_FORCEINLINE is crucial in Boost.Atomic, it cannot be replaced with inline lightly.

could you explain it why it is crucial, please

Last edited 8 years ago by olli (previous) (diff)

in reply to:  6 ; comment:7 by Andrey Semashev, 8 years ago

Replying to olli:

I can reproduce the error with gcc 4.8.2 - using boost::atomic<> and __transaction_atomic in the same app

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.

BOOST_FORCEINLINE is crucial in Boost.Atomic, it cannot be replaced with inline lightly.

could you explain it why it is crucial, please

It is commented in boost/atomic/detail/ops_gcc_atomic.hpp. In short, atomic<> 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.

in reply to:  7 comment:8 by olli, 8 years ago

Replying to andysem:

Replying to olli:

I can reproduce the error with gcc 4.8.2 - using boost::atomic<> and __transaction_atomic in the same app

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.

I do not use atomics inside __transaction_atomic - only some parts of the code using atomics (e.g. spinlocks) are replaced by __transaction_atomic

comment:9 by Andrey Semashev, 6 years ago

Resolution: wontfix
Status: newclosed

I don't think we will be able to work around this.

Note: See TracTickets for help on using tickets.