Modify

Ticket #6931 (closed Bugs: fixed)

Opened 2 years ago

Last modified 15 months ago

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

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

Change History

comment:1 Changed 2 years ago by viboes

  • Owner set to anthonyw
  • Component changed from None to thread

comment:2 Changed 22 months ago by viboes

  • Owner changed from anthonyw to viboes
  • Status changed from new to assigned

comment:3 Changed 22 months ago by viboes

  • Milestone changed from To Be Determined to Boost 1.51.0

Committed in trunk [79337]

comment:4 Changed 22 months ago by viboes

  • Status changed from assigned to closed
  • Resolution set to fixed

Committed revision [79373].

Changed 20 months ago by abrarov@…

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

comment:5 follow-up: ↓ 7 Changed 20 months 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 20 months ago by abrarov@…

  • Status changed from closed to reopened
  • Summary changed from mutex waits forwever with Intel Compiler and /debug:parallel to mutex waits forwever with Intel C++ Compiler XE 12.1.5.344 Build 20120612
  • Resolution fixed deleted
  • Version changed from Boost 1.49.0 to Boost 1.51.0
  • Milestone changed from Boost 1.51.0 to To Be Determined

comment:7 in reply to: ↑ 5 ; follow-ups: ↓ 8 ↓ 13 Changed 20 months 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 ; follow-up: ↓ 9 Changed 20 months 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 ; follow-up: ↓ 10 Changed 20 months 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 20 months 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 20 months ago by viboes

  • Milestone changed from To Be Determined to Boost 1.52.0

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

comment:12 Changed 20 months ago by viboes

  • Status changed from reopened to closed
  • Resolution set to fixed

Committed revision 80516.

comment:13 in reply to: ↑ 7 Changed 19 months 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 15 months ago by y.hoshizuki

  • Status changed from closed to reopened
  • Resolution fixed deleted

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 15 months ago by y.hoshizuki

this problem was already fixed by #7272. sorry.

comment:16 Changed 15 months ago by viboes

  • Status changed from reopened to closed
  • Resolution set to fixed
View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


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

 
Note: See TracTickets for help on using tickets.