Boost.Atomic on Windows, patch

Hi. I have noticed that boost/atomic/detail/generic-cas.hpp is directly including Windows.h header. I consider this problematic for WinSock using applications as Windows.h automatically pulls in Winsock.h, the WinSock 1 header. This is problematic because it requires users that want to use WinSock 2 to order their include of WinSock2.h before inclusion of Boost.Atomic. At this point in time anybody serious about sockets on Windows really do not want to use WinSock 1 but version 2 instead. So I suggest the attached patch. -- VZ

On Aug 2, 2012, at 9:31 AM, Václav Zeman <vhaisman@gmail.com> wrote:
Hi.
I have noticed that boost/atomic/detail/generic-cas.hpp is directly including Windows.h header. I consider this problematic for WinSock using applications as Windows.h automatically pulls in Winsock.h, the WinSock 1 header. This is problematic because it requires users that want to use WinSock 2 to order their include of WinSock2.h before inclusion of Boost.Atomic. At this point in time anybody serious about sockets on Windows really do not want to use WinSock 1 but version 2 instead. So I suggest the attached patch.
Thanks for the patch. I really hate those WinSock2 include dependencies! I have incorporated it into my own vendor branch of atomic.
-- VZ <boost.atomic.windows.patch.txt> _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

On 02.08.2012 17:31, Václav Zeman wrote:
I have noticed that boost/atomic/detail/generic-cas.hpp is directly including Windows.h header. I consider this problematic for WinSock using applications as Windows.h automatically pulls in Winsock.h, the WinSock 1 header. This is problematic because it requires users that want to use WinSock 2 to order their include of WinSock2.h before inclusion of Boost.Atomic. At this point in time anybody serious about sockets on Windows really do not want to use WinSock 1 but version 2 instead. So I suggest the attached patch. Why is neccessary to include the windows headers at all? Intrin.h seems to be enough: it declares _InterlockedCompareExchange and some other useful intrinics, and it does not use the winapi-related stuff.
Checked on MSVC 2008 and 2010. I remember that I had some problems with interlocked functions and intrinics several years ago (with MSVC6, probably), but now I cannot reproduce them. -- Sergey Cheban

On 3 August 2012 11:04, Sergey Cheban wrote:
On 02.08.2012 17:31, Václav Zeman wrote:
I have noticed that boost/atomic/detail/generic-cas.hpp is directly including Windows.h header. I consider this problematic for WinSock using applications as Windows.h automatically pulls in Winsock.h, the WinSock 1 header. This is problematic because it requires users that want to use WinSock 2 to order their include of WinSock2.h before inclusion of Boost.Atomic. At this point in time anybody serious about sockets on Windows really do not want to use WinSock 1 but version 2 instead. So I suggest the attached patch.
Why is neccessary to include the windows headers at all? Intrin.h seems to be enough: it declares _InterlockedCompareExchange and some other useful intrinics, and it does not use the winapi-related stuff.
Checked on MSVC 2008 and 2010. I remember that I had some problems with interlocked functions and intrinics several years ago (with MSVC6, probably), but now I cannot reproduce them. Both intrin.h and windows.h do declare the intrinsic functions using #pragma intrinsic. It look like a kind of double protection, making sure that the intrinsics will be available.
BTW, there is a typo in the patch in comment: WindSock2.h --> WinSock2.h -- VZ

Why is neccessary to include the windows headers at all? Intrin.h seems to be enough: it declares _InterlockedCompareExchange and some other useful intrinsics, and it does not use the winapi-related stuff.
Checked on MSVC 2008 and 2010. I remember that I had some problems with interlocked functions and intrinics several years ago (with MSVC6, probably), but now I cannot reproduce them. Both intrin.h and windows.h do declare the intrinsic functions using #pragma intrinsic. No. Windows.h does not declare _InterlockedCompareExchange at all. Instead, it declares InterlockedCompareExchange (without underscore)
On 03.08.2012 14:43, Václav Zeman wrote: that is not an intrinsic but a function implemented in the Kernel32.lib. For the x86, there is also an implementation in the kernel32.dll but the programs that were built with modern versions of the Windows SDK don't use it. The following does not work: #include <windows.h> void f() { long l; _InterlockedCompareExchange( &l, 0,0 ); //error C3861: '_InterlockedCompareExchange': identifier not found } So, windows.h and winsock2.h are useless for those who want to use _InterlockedCompareExchange. -- Sergey Cheban -- Sergey Cheban

On 08/03/2012 07:43 PM, Sergey Cheban wrote:
On 03.08.2012 14:43, Václav Zeman wrote:
Why is neccessary to include the windows headers at all? Intrin.h seems to be enough: it declares _InterlockedCompareExchange and some other useful intrinsics, and it does not use the winapi-related stuff.
Checked on MSVC 2008 and 2010. I remember that I had some problems with interlocked functions and intrinics several years ago (with MSVC6, probably), but now I cannot reproduce them. Both intrin.h and windows.h do declare the intrinsic functions using #pragma intrinsic. No. Windows.h does not declare _InterlockedCompareExchange at all. Instead, it declares InterlockedCompareExchange (without underscore) that is not an intrinsic but a function implemented in the Kernel32.lib. For the x86, there is also an implementation in the kernel32.dll but the programs that were built with modern versions of the Windows SDK don't use it. I can see the #pragma intrinsic bits in WinNT.h which is included by WinDef.h which is included by Windows.h. But maybe there is some macro symbols trickery that make it ineffective.
The following does not work:
#include <windows.h>
void f() { long l; _InterlockedCompareExchange( &l, 0,0 ); //error C3861: '_InterlockedCompareExchange': identifier not found }
So, windows.h and winsock2.h are useless for those who want to use _InterlockedCompareExchange.
-- VZ

[Sergey Cheban]
Why is neccessary to include the windows headers at all? Intrin.h seems to be enough: it declares _InterlockedCompareExchange and some other useful intrinics, and it does not use the winapi-related stuff.
FYI, VC11's <atomic> includes <intrin.h>. Works fine for us. (Note, however, that it was very problematic to get the STL to drag in <intrin.h> in VC9. Those bugs were fixed in VC10. Although we have the luxury of targeting a single version, you might care.) Stephan T. Lavavej Visual C++ Libraries Developer
participants (4)
-
Daniel Larimer
-
Sergey Cheban
-
Stephan T. Lavavej
-
Václav Zeman