64-bit Atom statements for a 32-bit application on 64-bit Windows

So, this document says that running 64-bit Windows gives you 64-bit atomicity: http://msdn.microsoft.com/en-us/library/windows/desktop/ms684122%28v=vs.85%29. aspx

This message indicates that you need to run a 64-bit application in order to get 64-bit atomicity: 32/64 bit atomicity

I am developing a Win32 console application. So, if I understand correctly, I have to use 32-bit types to get atomicity, right? I can not assume that the 64-bit type has atomic write / read?

+1
windows visual-c ++ atomicity 32bit-64bit
Dec 17 '14 at 19:46
source share
1 answer

In a 64-bit application, 64-bit read / write operations can be automatic, because the compiler can use the extended x64 instruction set, which has atomic 64-bit read / write operations.

In 32-bit code on 64-bit OS and hardware, on the other hand, if an application needs to read / write 64-bit data, there are no 64-bit read / write instructions available for the compiler to generate (at least) two operations read / write. Since the OS could pre-clean the process between two reads / writes, you should use the Interlockedxxx API.

Note. You can create 64-bit Win32 console applications if you want. In this case, the compiler can generate code that uses 64-bit read / write operations.

Of course, since your code may want to read or write data types that are larger than 64 bits (e.g. SSE2 / 3, AVX, etc.), so several read / write operations are required, you should use the appropriate functions to ensure that the required operations are atomic.

Instead of assuming that you can rely on the compiler to do the right thing for your specific scenario, I would recommend using the necessary API and internal properties to explicitly declare which of your MUST operations will be atomic, so you all whether your code will be compiled for x64, x64, ARM, MIPS, etc.

+4
Dec 17 '14 at 20:20
source share



All Articles