씹어먹는 C++ 강좌 사이트에서 아토믹 변수부분을 읽고 문제 1번 부터 막혔어..

내가 제데로 이해를 못한걸까....?


컴공과 지잡 인데 이정도 머가리론 플머 못함????

도저히 이해가 안가...




int n = 0;

std::atomic atm;

bool a = true;

int main()

{


std::thread t1([] { 

for (int i = 0; i

{

while (true)

{

if (atm.compare_exchange_strong(a, false, std::memory_order::memory_order_seq_cst)) break;

}

atm.store(false, std::memory_order::memory_order_seq_cst);

printf("%s", atm.load(std::memory_order::memory_order_seq_cst) ? "true\n" : "");

n++;

atm.store(true, std::memory_order::memory_order_seq_cst);

}

});


std::thread t2([] { 

for (int i = 0; i

{

while (true)

{

if (atm.compare_exchange_strong(a, false, std::memory_order::memory_order_seq_cst)) break;

}

atm.store(false, std::memory_order::memory_order_seq_cst);

printf("%s", atm.load(std::memory_order::memory_order_seq_cst) ? "true\n" : "");

n++;

atm.store(true, std::memory_order::memory_order_seq_cst);

}

});


t1.join();

t2.join();


printf("%d\n", n);


}




왜 atm.load(std::memory_order::memory_order_seq_cst) 이게 자꾸 True가 오는거야



씨발!!!