문제

내가 알고있는에서라도/PosiX 시스템,거기에는 원자-compare-and-swap C/C++코드를 통해 g++.

그러나 내가 필요로 하지 않을 비교-내려 자동으로 스왑 두 값이 있습니다.이 있는 원자 스왑 작업에 사용할 수 있습니까?[Everythign 을 찾을 수 있습니 atomic_compare_and_swap...나는 그냥을 하고 싶은 스왑지 않고,비교].

감사합니다!

도움이 되었습니까?

해결책

"잠금 xchg"intel 어셈블리의 지침은 아마도 당신이 원하는 나만 생각하지 말라 거기는 GCC 래퍼 기능을 이 휴대용입니다.그 때문에 붙어를 사용하여 어셈블리는 인라인(사용)사용하거나 비교하고 교환을 강제로 비교하 true(inneficient).도움이 되기를 바랍:-)

다른 팁

GCC는 (혼란스럽게 지명 된) 일부 프로세서 에서이 작업을 제공합니다. __sync_lock_test_and_set. GCC 문서에서 :

 This builtin, as described by Intel, is not a traditional
 test-and-set operation, but rather an atomic exchange operation.
 It writes VALUE into `*PTR', and returns the previous contents of
 `*PTR'.

 Many targets have only minimal support for such locks, and do not
 support a full exchange operation.  In this case, a target may
 support reduced functionality here by which the _only_ valid value
 to store is the immediate constant 1.  The exact value actually
 stored in `*PTR' is implementation defined.

그러나 전체 스왑 작업은 X86-32 및 X86-64에서 지원되며 효과적으로 제공합니다. lock xchg 래퍼는 그렇지 않으면 쓸 필요가 있습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top