Opened 9 years ago

Last modified 9 years ago

#8593 new Patches

enable std::atomic with clang / libc++

Reported by: reakinator@… Owned by: timblechmann
Milestone: To Be Determined Component: lockfree
Version: Boost 1.52.0 Severity: Problem
Keywords: Cc: reakinator@…

Description

Attatched is a simple patch that checks if we're usng a version of clang / libc++ that has <atomic> support.

The:

#if defined(_LIBCPP_VERSION) && __has_include( <atomic> )

is on a second line because I previously had problems with the has_include( <> ) macro when this code is interpreted by MSVC compiler - it seems to want to process the entire line despite the first check failing.

Attachments (1)

lockfree_atomic_libcpp.patch (616 bytes ) - added by reakinator@… 9 years ago.
lockfree/detail/atomic.hpp patch enabling <atomic> for libc++

Download all attachments as: .zip

Change History (6)

by reakinator@…, 9 years ago

lockfree/detail/atomic.hpp patch enabling <atomic> for libc++

comment:1 by timblechmann, 9 years ago

unfortunately this does not work on linux:

/usr/include/c++/v1/atomic:623:58: error: no viable conversion from 'boost::lockfree::detail::tagged_index' to '_Atomic(boost::lockfree::detail::tagged_index)'
    _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __a_(__d) {}
                                                         ^    ~~~
/usr/include/c++/v1/atomic:727:51: note: in instantiation of member function 'std::__1::__atomic_base<boost::lockfree::detail::tagged_index, false>::__atomic_base' requested here
    _LIBCPP_CONSTEXPR atomic(_Tp __d) _NOEXCEPT : __base(__d) {}
                                                  ^
../../../boost/lockfree/detail/freelist.hpp:404:9: note: in instantiation of member function 'std::__1::atomic<boost::lockfree::detail::tagged_index>::atomic' requested here
        pool_(tagged_index(static_cast<index_t>(count), 0))
        ^

comment:2 by reakinator@…, 9 years ago

Agh, as luck would have it I'm only using lockfree::spsc_queue, which doesn't have this problem (both lockfree stack and queue do).

Can you tell why the conversion can't be made? libc++ is known to be pretty strict with standards (more than gcc), but hopefully we can narrow down what needs to be fixed.

comment:3 by reakinator@…, 9 years ago

I found the following thread when doing some research:

http://clang-developers.42468.n3.nabble.com/RFC-atomic-support-for-gcc-4-7-compatibility-td3900609.html

My hunch is that point 2 on that list ("relax the requirement to the type being either _Atomic or trivially copyable") was not implemented, or tagged_ptr is not trivially copyable.

comment:4 by Richard Eakin <reakinator@…>, 9 years ago

Hm, appears it is a clang bug, H.Hinnant submitted a patch a few hours after I reported it...

http://lists.cs.uiuc.edu/pipermail/cfe-dev/2013-May/029771.html

I guess this has to go on the back burner for now... when there is a way to verify we are using the updated version of libc++, I'll update.

comment:5 by timblechmann, 9 years ago

gcc used to have the same problem ... hopefully this patch makes it into a libc++ release in the near future ... until then, boost.atomic is the way to go ...

Note: See TracTickets for help on using tickets.