[Boost-bugs] [Boost C++ Libraries] #6931: mutex waits forwever with Intel Compiler and /debug:parallel

Subject: [Boost-bugs] [Boost C++ Libraries] #6931: mutex waits forwever with Intel Compiler and /debug:parallel
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-05-22 21:17:24


#6931: mutex waits forwever with Intel Compiler and /debug:parallel
-------------------------------------------+--------------------------------
 Reporter: Orin Eman <orine@…> | Type: Bugs
   Status: new | Milestone: To Be Determined
Component: None | Version: Boost 1.49.0
 Severity: Problem | Keywords: mutex intel compiler
-------------------------------------------+--------------------------------
 The following in thread/win32/thread_primitives.hpp doesn't work with the
 latest Intel Compiler and the /debug:parallel option:

             inline bool interlocked_bit_test_and_set(long* x,long bit)
             {
                 __asm {
                     mov eax,bit;
                     mov edx,x;
                     lock bts [edx],eax;
                     setc al;
                 };
             }

             inline bool interlocked_bit_test_and_reset(long* x,long bit)
             {
                 __asm {
                     mov eax,bit;
                     mov edx,x;
                     lock btr [edx],eax;
                     setc al;
                 };
             }

 The Intel Compiler is immediately following the "setc al;" instructions
 with "mov eax, esp", trashing the return value.

 I'll report the problem to Intel, but I'm pretty sure that they will say
 that the behaviour the above code relies on isn't guaranteed by any
 compiler.

 The fix is simple:

             inline bool interlocked_bit_test_and_set(long* x,long bit)
             {
                 bool ret;
                 __asm {
                     mov eax,bit;
                     mov edx,x;
                     lock bts [edx],eax;
                     setc al;
                     mov ret, al
                 };
                 return ret;
             }

             inline bool interlocked_bit_test_and_reset(long* x,long bit)
             {
                 bool ret;
                 __asm {
                     mov eax,bit;
                     mov edx,x;
                     lock btr [edx],eax;
                     setc al;
                     mov ret, al
                };
                return ret;
            }

 Let the compiler optimize out the extra move should it so desire...

 Orin.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/6931>
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:09 UTC