#include "iostream"
#include "atomic"
#include <thread>
#include <vector>
using namespace std;
std::atomic<int> value(0);
void setValue(int x)
{
value.store(x, std::memory_order_relaxed);
}
void printValue()
{
int x;
do{
x= value.load(std::memory_order_relaxed);
}while(x == 0);
cout << " value : " << x << endl;
}
int main()
{
thread t1(printValue);
thread t2(setValue, 100);
t1.join();
t2.join();
getchar();
return 0;
}
atomic 及内存序
最新推荐文章于 2025-08-11 14:46:01 发布
470

被折叠的 条评论
为什么被折叠?



