Modify

Opened 5 years ago

Closed 5 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@… 5 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 Changed 5 years ago by viboes

Component: Nonethread
Owner: set to Anthony Williams

comment:2 Changed 5 years ago by viboes

Owner: changed from Anthony Williams to viboes
Status: newassigned

comment:3 Changed 5 years ago by viboes

Milestone: To Be DeterminedBoost 1.51.0

Committed in trunk [79337]

comment:4 Changed 5 years ago by viboes

Resolution: fixed
Status: assignedclosed

Committed revision [79373].

Changed 5 years ago by abrarov@…

Attachment: intel_12_1_mutex.patch added

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

comment:5 Changed 5 years ago by 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.

comment:6 Changed 5 years ago by abrarov@…

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

comment:7 in reply to:  5 ; Changed 5 years ago by 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.

comment:8 in reply to:  7 ; Changed 5 years ago by 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.

comment:9 in reply to:  8 ; Changed 5 years ago by viboes

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 in reply to:  9 Changed 5 years ago by abrarov@…

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 Changed 5 years ago by viboes

Milestone: To Be DeterminedBoost 1.52.0

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

comment:12 Changed 5 years ago by viboes

Resolution: fixed
Status: reopenedclosed

Committed revision 80516.

comment:13 in reply to:  7 Changed 5 years ago by orine@…

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 Changed 5 years ago by y.hoshizuki

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 Changed 5 years ago by y.hoshizuki

this problem was already fixed by #7272. sorry.

comment:16 Changed 5 years ago by viboes

Resolution: fixed
Status: reopenedclosed

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain viboes.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.