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: | 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)
Change History (17)
comment:1 by , 10 years ago
Component: | None → thread |
---|---|
Owner: | set to |
comment:2 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 10 years ago
Milestone: | To Be Determined → Boost 1.51.0 |
---|
comment:4 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Committed revision [79373].
by , 10 years ago
Attachment: | intel_12_1_mutex.patch added |
---|
Patch for Intel C++ Compiler XE 12.1 and boost::mutex on Windows
follow-up: 7 comment:5 by , 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 , 10 years ago
Milestone: | Boost 1.51.0 → To Be Determined |
---|---|
Resolution: | fixed |
Status: | closed → reopened |
Summary: | mutex waits forwever with Intel Compiler and /debug:parallel → mutex waits forwever with Intel C++ Compiler XE 12.1.5.344 Build 20120612 |
Version: | Boost 1.49.0 → Boost 1.51.0 |
follow-ups: 8 13 comment:7 by , 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.
follow-up: 9 comment:8 by , 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.
follow-up: 10 comment:9 by , 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?
comment:10 by , 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 , 10 years ago
Milestone: | To Be Determined → Boost 1.52.0 |
---|
Patch applied on trunk. Committed in trunk posix part [80449]
comment:12 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
Committed revision 80516.
comment:13 by , 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 , 10 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
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:16 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
Committed in trunk [79337]