0
글로벌 : 스레드 A의스왑에 경쟁 조건이 있습니까?
std::atomic<T*> a, b;
: 스레드 B에
// this like std::swap(a, b), but is it atomic?
a.exchange(b.exchange(a));
: 원자 조작
T* p = a.load();
doSomethine(p);
글로벌 : 스레드 A의스왑에 경쟁 조건이 있습니까?
std::atomic<T*> a, b;
: 스레드 B에
// this like std::swap(a, b), but is it atomic?
a.exchange(b.exchange(a));
: 원자 조작
T* p = a.load();
doSomethine(p);
시퀀스 원자 아니다. b.exchange
과 a.exchange
사이에 뭔가가 발생할 수 있으며 a
과 b
이 모두 동일한 값 (원래 값 : a
)을 갖게됩니다.
당신이 원하지 않는 경우
는 잠금의 몇 가지 유형을 사용합니다.