고수님들... C++ InterlockedComapreExchange128 msdn 소스에서 에러가 납니다..
조회수 718회
https://docs.microsoft.com/en-us/cpp/intrinsics/interlockedcompareexchange128?view=vs-2017
msdn 문서는 다음과 같고, Release x64 , 최적화 옵션 끄고 사용했습니다.. InterlockedCompareExchange128 함수에서 0xFFFFFFFFFFFFFFFF 위치 엑세스 위반이 일어 납니다.. 그런대 이유를 모르겠어요! 조사식으로 보면 전역,로컬 전부 멀쩡하거든요 ㅠㅠ
//#include
//#include
typedef struct _LARGE_INTEGER_128 { __int64 Int[2]; } LARGE_INTEGER_128, *PLARGE_INTEGER_128;
volatile LARGE_INTEGER_128 BigInt;
// This AtomicOp() function atomically performs:
// BigInt.Int[1] += BigInt.Int[0]
// BigInt.Int[0] += 1
void AtomicOp()
{
LARGE_INTEGER_128 Comparand;
Comparand.Int[0] = BigInt.Int[0];
Comparand.Int[1] = BigInt.Int[1];
do {
; // nothing
} while (_InterlockedCompareExchange128(BigInt.Int,
Comparand.Int[0] + Comparand.Int[1],
Comparand.Int[0] + 1,
Comparand.Int) == 0);
}
// In a real application, several threads contend for the value
// of BigInt.
// Here we focus on the compare and exchange for simplicity.
int main(void)
{
BigInt.Int[1] = 23;
BigInt.Int[0] = 11;
AtomicOp();
printf("BigInt.Int[1] = %d, BigInt.Int[0] = %d\n",
BigInt.Int[1], BigInt.Int[0]);
}
-
(•́ ✖ •̀)
알 수 없는 사용자
댓글 입력