Windows@i386ã§ã®atomic 64bit store
Windows@i386ã§ã®atomic 64bit storeã_InterlockedCompareExchange64ã使ã£ãã»ããããã®ããªï¼ã ããããã¡ããã¨åä½ãã¦ãã®ãããâ¦ããã³ãæ±ãã
#include <windows.h> #include <stdio.h> #define int32_t INT32 #define uint32_t UINT32 #define int64_t INT64 #define uint64_t UINT64 void atomic_set_64bit(uint64_t *p, uint64_t v) { uint32_t v1, v2; v1 = *(((uint32_t *)&(v))+0); v2 = *(((uint32_t *)&(v))+1); __asm { _set_loop: mov esi, p mov ebx, v1 mov ecx, v2 mov eax, dword ptr [esi] mov edx, dword ptr [esi + 4] lock cmpxchg8b qword ptr [esi] jnz _set_loop } } int main(int argc, char *argv) { uint64_t i = 0x0123456789abcdefULL, j = 0xfedcba9876543210ULL; printf("%08llx\n", i); printf("%08llx\n", j); atomic_set_64bit(&i, j); printf("%08llx\n", i); }