Opened 11 years ago

Last modified 9 years ago

#6325 new Support Requests

InterlockedExchangeAdd improperly identified as managed code.

Reported by: filmorependrgn@… Owned by: chris_kohlhoff
Milestone: To Be Determined Component: asio
Version: Boost 1.48.0 Severity: Problem
Keywords: InterlockedExchangeAdd Cc:

Description

There is a Microsoft C++ bug that causes InterlockedExchangeAdd to improperly be identified as managed code instead of native code. A workaround is mentioned here: http://connect.microsoft.com/VisualStudio/feedback/details/629931/internal-compiler-error-c1001-when-compiling-opencv-2-1-2-2-with-c-cli-64-bit

This prevents programs from being compiled correctly in VS2010

The workaround is implemented below:

boost\asio\detail\win_thread.hpp:45

return (1?::InterlockedExchangeAdd(&terminate_threads_, 0) != 0: 0!= InterlockedExchangeAdd64((volatile LONG64 *)0,(LONG64) 0));

and

boost\asio\detail\impl\winsock_init.ipp:54

long result = (1?::InterlockedExchangeAdd(&d.result_, 0) : InterlockedExchangeAdd64((volatile LONG64 *)0,(LONG64) 0));

Implementing the above fix allows the programs to compile with a warning:

warning C4793: 'boost::asio::detail::win_thread_base<boost::asio::detail::win_thread>::terminate_threads' : function compiled as native :
1>  	Found an intrinsic not supported in managed code

and

warning C4793: 'boost::asio::detail::winsock_init_base::throw_on_error' : function compiled as native :
1>  	Found an intrinsic not supported in managed code

This is a workaround for a compiler bug, so I don't know how the boost development team wants to treat this.

Using VS2010 compiling for a 64-bit target (amd64)

Change History (3)

comment:1 by chris_kohlhoff, 10 years ago

This fix is not ok. The InterlockedExchangeAdd64 function is only available from Windows Vista on. Please propose an alternative patch.

comment:2 by anonymous, 9 years ago

This bug still exists in VS2012. I have solved my issue using:

#pragma managed(push, off)

LONG CTimerBase::GetCount() {

return InterlockedExchangeAdd( &m_mutexCount, 0 );

}

#pragma managed(pop)

comment:3 by chris_kohlhoff, 9 years ago

Can you please confirm whether this patch would fix the issue (without breaking anything else)?

Index: boost/asio/detail/pop_options.hpp
===================================================================
--- boost/asio/detail/pop_options.hpp   (revision 84379)
+++ boost/asio/detail/pop_options.hpp   (working copy)
@@ -94,5 +94,8 @@
 
 # pragma warning (pop)
 # pragma pack (pop)
+# if (_MSC_VER >= 1300)
+#  pragma managed (pop)
+# endif
 
 #endif
Index: boost/asio/detail/push_options.hpp
===================================================================
--- boost/asio/detail/push_options.hpp  (revision 84379)
+++ boost/asio/detail/push_options.hpp  (working copy)
@@ -123,5 +123,8 @@
 # if !defined(_MT)
 #  error Multithreaded RTL must be selected.
 # endif // !defined(_MT)
+# if (_MSC_VER >= 1300)
+#  pragma managed (push, off)
+# endif
 
 #endif
Note: See TracTickets for help on using tickets.