[Boost-bugs] [Boost C++ Libraries] #7892: boost.atomic misbehaves with Apple clang version 4.1 and -O2

Subject: [Boost-bugs] [Boost C++ Libraries] #7892: boost.atomic misbehaves with Apple clang version 4.1 and -O2
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-01-14 21:19:36


#7892: boost.atomic misbehaves with Apple clang version 4.1 and -O2
--------------------------------------------------------+-------------------
 Reporter: Andreas Beisler <ebfx@…> | Owner: timblechmann
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: atomic
  Version: Boost Release Branch | Severity: Problem
 Keywords: |
--------------------------------------------------------+-------------------
 There seems to be an issue, when assigning to an atomic in a "while
 (true)" loop (without break statement!).

 {{{
 #include <boost/atomic.hpp>

 void this_works()
 {
     boost::atomic_bool b(false);
     std::cout << b << std::endl; // 0
     b = true;
     std::cout << b << std::endl; // 1
 }

 void this_works_too()
 {
     boost::atomic_bool b(false);
     while (true)
     {
         std::cout << b << std::endl; // 0
         b = true;
         std::cout << b << std::endl; // 1
         break;
     }
 }

 void this_doesnt_work()
 {
     boost::atomic_bool b(false);
     while (true)
     {
         std::cout << b << std::endl; // 0
         b = true;
         std::cout << b << 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;
 }
 }}}

 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.

 Best regards,
 Andreas

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/7892>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:11 UTC