Boost C++ Libraries: Ticket #6325: InterlockedExchangeAdd improperly identified as managed code. https://svn.boost.org/trac10/ticket/6325 <p> There is a Microsoft C++ bug that causes <a class="missing wiki">InterlockedExchangeAdd</a> to improperly be identified as managed code instead of native code. A workaround is mentioned here: <a class="ext-link" href="http://connect.microsoft.com/VisualStudio/feedback/details/629931/internal-compiler-error-c1001-when-compiling-opencv-2-1-2-2-with-c-cli-64-bit"><span class="icon">​</span>http://connect.microsoft.com/VisualStudio/feedback/details/629931/internal-compiler-error-c1001-when-compiling-opencv-2-1-2-2-with-c-cli-64-bit</a> </p> <p> This prevents programs from being compiled correctly in VS2010 </p> <p> The workaround is implemented below: </p> <p> boost\asio\detail\win_thread.hpp:45 </p> <pre class="wiki">return (1?::InterlockedExchangeAdd(&amp;terminate_threads_, 0) != 0: 0!= InterlockedExchangeAdd64((volatile LONG64 *)0,(LONG64) 0)); </pre><p> and </p> <p> boost\asio\detail\impl\winsock_init.ipp:54 </p> <pre class="wiki">long result = (1?::InterlockedExchangeAdd(&amp;d.result_, 0) : InterlockedExchangeAdd64((volatile LONG64 *)0,(LONG64) 0)); </pre><p> Implementing the above fix allows the programs to compile with a warning: </p> <pre class="wiki">warning C4793: 'boost::asio::detail::win_thread_base&lt;boost::asio::detail::win_thread&gt;::terminate_threads' : function compiled as native : 1&gt; Found an intrinsic not supported in managed code </pre><p> and </p> <pre class="wiki">warning C4793: 'boost::asio::detail::winsock_init_base::throw_on_error' : function compiled as native : 1&gt; Found an intrinsic not supported in managed code </pre><p> This is a workaround for a compiler bug, so I don't know how the boost development team wants to treat this. </p> <p> Using VS2010 compiling for a 64-bit target (amd64) </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6325 Trac 1.4.3 chris_kohlhoff Tue, 29 May 2012 01:28:36 GMT <link>https://svn.boost.org/trac10/ticket/6325#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6325#comment:1</guid> <description> <p> This fix is not ok. The <code>InterlockedExchangeAdd64</code> function is only available from Windows Vista on. Please propose an alternative patch. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Wed, 24 Apr 2013 08:07:44 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6325#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6325#comment:2</guid> <description> <p> This bug still exists in VS2012. I have solved my issue using: </p> <p> #pragma managed(push, off) </p> <p> LONG CTimerBase::<a class="missing wiki">GetCount</a>() { </p> <blockquote> <p> return <a class="missing wiki">InterlockedExchangeAdd</a>( &amp;m_mutexCount, 0 ); </p> </blockquote> <p> } </p> <p> #pragma managed(pop) </p> </description> <category>Ticket</category> </item> <item> <dc:creator>chris_kohlhoff</dc:creator> <pubDate>Fri, 24 May 2013 03:15:34 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6325#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6325#comment:3</guid> <description> <p> Can you please confirm whether this patch would fix the issue (without breaking anything else)? </p> <pre class="wiki">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 &gt;= 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 &gt;= 1300) +# pragma managed (push, off) +# endif #endif </pre> </description> <category>Ticket</category> </item> </channel> </rss>