Opened 10 years ago

Closed 10 years ago

#6931 closed Bugs (fixed)

mutex waits forwever with Intel C++ Compiler XE 12.1.5.344 Build 20120612

Reported by: Orin Eman <orine@…> Owned by: viboes
Milestone: Boost 1.52.0 Component: thread
Version: Boost 1.51.0 Severity: Problem
Keywords: mutex intel compiler Cc:

Description

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.

Attachments (1)

intel_12_1_mutex.patch (608 bytes ) - added by abrarov@… 10 years ago.
Patch for Intel C++ Compiler XE 12.1 and boost::mutex on Windows

Download all attachments as: .zip

Change History (17)

comment:1 by viboes, 10 years ago

Component: Nonethread
Owner: set to Anthony Williams

comment:2 by viboes, 10 years ago

Owner: changed from Anthony Williams to viboes
Status: newassigned

comment:3 by viboes, 10 years ago

Milestone: To Be DeterminedBoost 1.51.0

Committed in trunk [79337]

comment:4 by viboes, 10 years ago

Resolution: fixed
Status: assignedclosed

Committed revision [79373].

by abrarov@…, 10 years ago

Attachment: intel_12_1_mutex.patch added

Patch for Intel C++ Compiler XE 12.1 and boost::mutex on Windows

comment:5 by abrarov@…, 10 years ago

Hi, Orin and viboes. I have the same problem at my project (http://sourceforge.net/projects/asio-samples, project echo_server) with Intel C++ Compiler XE Version 12.1.5.344 Build 20120612, Boost C++ Libraries 1.51 and Windows 7 SP1 Pro. It seems (by means of disassembly view) that compiler optimizes asm block into something like:

asm {
  mov edx, x; 
  mov ret, edx;
}

The only solution that helps me is located at intel_12_1_mutex.patch (attached).

Regards, Marat.

comment:6 by abrarov@…, 10 years ago

Milestone: Boost 1.51.0To Be Determined
Resolution: fixed
Status: closedreopened
Summary: mutex waits forwever with Intel Compiler and /debug:parallelmutex waits forwever with Intel C++ Compiler XE 12.1.5.344 Build 20120612
Version: Boost 1.49.0Boost 1.51.0

in reply to:  5 ; comment:7 by viboes, 10 years ago

Replying to abrarov@…:

Hi, Orin and viboes. I have the same problem at my project (http://sourceforge.net/projects/asio-samples, project echo_server) with Intel C++ Compiler XE Version 12.1.5.344 Build 20120612, Boost C++ Libraries 1.51 and Windows 7 SP1 Pro. It seems (by means of disassembly view) that compiler optimizes asm block into something like:

asm {
  mov edx, x; 
  mov ret, edx;
}

The only solution that helps me is located at intel_12_1_mutex.patch (attached).

Regards, Marat.

Orin please, let me know if this patch works for you.

in reply to:  7 ; comment:8 by abrarov@…, 10 years ago

Replying to viboes:

Orin please, let me know if this patch works for you.

Actually it is only a workaround that switches Intel compiler to use _interlockedbittestandset/_interlockedbittestandreset instead of inline asm.

in reply to:  8 ; comment:9 by viboes, 10 years ago

Replying to abrarov@…:

Replying to viboes:

Orin please, let me know if this patch works for you.

Actually it is only a workaround that switches Intel compiler to use _interlockedbittestandset/_interlockedbittestandreset instead of inline asm.

Well if the assembler doesn't works and no body know how to fix it, I could consider this a fix, don't you?

in reply to:  9 comment:10 by abrarov@…, 10 years ago

Replying to viboes:

Well if the assembler doesn't works and no body know how to fix it, I could consider this a fix, don't you?

I consider it a compiler bug that can not be worked around with inline asm. Being the only solution for Boost to work correctly, it can be named "fix".

comment:11 by viboes, 10 years ago

Milestone: To Be DeterminedBoost 1.52.0

Patch applied on trunk. Committed in trunk posix part [80449]

comment:12 by viboes, 10 years ago

Resolution: fixed
Status: reopenedclosed

Committed revision 80516.

in reply to:  7 comment:13 by orine@…, 10 years ago

Replying to viboes:

Replying to abrarov@…:

Hi, Orin and viboes. I have the same problem at my project (http://sourceforge.net/projects/asio-samples, project echo_server) with Intel C++ Compiler XE Version 12.1.5.344 Build 20120612, Boost C++ Libraries 1.51 and Windows 7 SP1 Pro. It seems (by means of disassembly view) that compiler optimizes asm block into something like:

asm {
  mov edx, x; 
  mov ret, edx;
}

The only solution that helps me is located at intel_12_1_mutex.patch (attached).

Regards, Marat.

Orin please, let me know if this patch works for you.

I was on vacation and didn't get chance. I would have agreed with it being a fix rather than a workaround given your experience.

Orin.

comment:14 by y.hoshizuki, 10 years ago

Resolution: fixed
Status: closedreopened

this patch ([79337]) breaks mutex, using Intel Composer XE 2013.

semicolon is the comment for MASM format.

icl.exe compiles

__asm {
    mov eax,bit; mov edx,x; lock bts [edx],eax; setc al; mov ret, al
};

to

; Begin ASM
  00004 8b 45 0c         mov eax, DWORD PTR [12+ebp]            ;C:\boost-1.51.0\boost/thread/win32/thread_primitives.hpp:354.21
; End ASM

, and this code is meaningless.

comment:15 by y.hoshizuki, 10 years ago

this problem was already fixed by #7272. sorry.

comment:16 by viboes, 10 years ago

Resolution: fixed
Status: reopenedclosed
Note: See TracTickets for help on using tickets.