我对C ++标准和更一般的计算机体系结构都有疑问。想象以下代码:
#include <atomic>
#include <thread>
std::atomic<int> a {0};
int main () {
std::thread t1([&a](){
int i = 1;
int ao = a.load();
while(!a.compare_exchange_weak(ao, i));
}), t2([&a](){
int i = 1;
int ao = a.load();
while(a.compare_exchange_weak(ao, i));
});
t1.join();
t2.join();
return 0;
}
我有两个问题: