69,371
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <atomic>
#include <thread>
using namespace std;
atomic_llong a{ 0 };
void func1() {
for (int i = 0; i < 100000; i++) {
++a;
}
}
void func2() {
for (int i = 0; i < 100000; i++)
{
--a;
}
}
int main()
{
thread t1(func1);
thread t2(func2);
t1.join();
t2.join();
cout << a << endl;
}