Boost C++ Libraries: Ticket #3377: interlocked pointer exchanges cause warnings with mingw64 https://svn.boost.org/trac10/ticket/3377 <p> With a gcc build targeting Win64 (specifically <a class="ext-link" href="http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Release%20for%20GCC%204.4.0/mingw-w64_x86-64_linux64-4.4.0-1.tar.bz2/download"><span class="icon">​</span>http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Release%20for%20GCC%204.4.0/mingw-w64_x86-64_linux64-4.4.0-1.tar.bz2/download</a>), I'm seeing warnings like this: </p> <p> /home/martind/work/unicorn/include/x86_64_mingw32w64/boost/thread/win32/interlocked_read.hpp: In function 'void boost::detail::interlocked_write_release(void* volatile*, void*)': /home/martind/work/unicorn/include/x86_64_mingw32w64/boost/thread/win32/interlocked_read.hpp:71: error: cast from 'void*' to 'long int' loses precision ... /home/martind/work/unicorn/include/x86_64_mingw32w64/boost/thread/win32/basic_timed_mutex.hpp: In member function 'void* boost::detail::basic_timed_mutex::get_event()': /home/martind/work/unicorn/include/x86_64_mingw32w64/boost/thread/win32/basic_timed_mutex.hpp:152: error: cast from 'void*' to 'long int' loses precision cc1plus: warnings being treated as errors </p> <p> The warnings come from the casts here in boost/detail/interlocked.hpp: </p> <p> # define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(dest,exchange,compare) \ </p> <blockquote> <p> ((void*)BOOST_INTERLOCKED_COMPARE_EXCHANGE((long volatile*)(dest),(long)(exchange),(long)(compare))) </p> </blockquote> <p> # define BOOST_INTERLOCKED_EXCHANGE_POINTER(dest,exchange) \ </p> <blockquote> <p> ((void*)BOOST_INTERLOCKED_EXCHANGE((long volatile*)(dest),(long)(exchange))) </p> </blockquote> <p> On Win64, I see that sizeof(long) == 4 but sizeof(void*) == 8, so the compiler is right to warn. Elsewhere in this file, <a class="missing wiki">InterlockedCompareExchangePointer</a> and <a class="missing wiki">InterlockedExchangePointer</a> are conditionally used to implement these macros. Comments I found elsewhere suggested that this is done conditionally because these functions aren't available in very old platform SDKs and, indeed, MSDN says that they only became available with Windows 2000. Perhaps Win64 can be assumed to have these functions available, as is assumed earlier in the file when compiling with MSVC. gcc for Win64 is a relatively new development without wide deployment, which could explain why the branch that handles <span class="underline">CYGWIN</span> etc doesn't yet cope. </p> <p> In the attached patch, I've used the same condition for detecting Win64 as used in the MSVC part of the file. That means that I've changed the behavior for IA64 as well as AMD64, despite having no means to test IA64. </p> <p> I see interlocked.hpp is used by interprocess, smart_ptr and thread but I'm not sure which Component it "belongs" to, so I've left that set to None. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/3377 Trac 1.4.3 mdorey@… Mon, 31 Aug 2009 21:36:46 GMT attachment set https://svn.boost.org/trac10/ticket/3377 https://svn.boost.org/trac10/ticket/3377 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">interlocked.hpp.patch</span> </li> </ul> <p> use Interlocked(Compare)?<a class="missing wiki">ExchangePointer</a> for mingw64 </p> Ticket Marshall Clow Sun, 06 Jun 2010 15:25:54 GMT milestone changed; owner set https://svn.boost.org/trac10/ticket/3377#comment:1 https://svn.boost.org/trac10/ticket/3377#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">Peter Dimov</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.41.0</span> → <span class="trac-field-new">To Be Determined</span> </li> </ul> Ticket viboes Mon, 07 Jun 2010 14:45:17 GMT <link>https://svn.boost.org/trac10/ticket/3377#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3377#comment:2</guid> <description> <p> Can this be assigned to shared_ptr component? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Marshall Clow</dc:creator> <pubDate>Mon, 07 Jun 2010 14:52:09 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3377#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3377#comment:3</guid> <description> <p> <em>&gt;Can this be assigned to shared_ptr component?</em><br /> I don't know; if I was sure, I would have done so.... </p> <p> Peter - what do you think? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Mon, 07 Jun 2010 15:08:43 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3377#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3377#comment:4</guid> <description> <p> These particular macros have, I believe, been added by Anthony Williams for use in Boost.Thread. So maybe Anthony is the person who needs to review and test the patch. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Anthony Williams</dc:creator> <pubDate>Mon, 07 Jun 2010 15:46:29 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/3377#comment:5 https://svn.boost.org/trac10/ticket/3377#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> I've applied the patch to trunk. </p> Ticket