We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 45f1db4 commit 4f3fff1Copy full SHA for 4f3fff1
atomic.cpp
@@ -0,0 +1,31 @@
1
+#include <iostream>
2
+#include <atomic>
3
+#include <thread>
4
+
5
6
+std::atomic<int> foo = 0;
7
8
+void set_foo(int x)
9
+{
10
+ foo = x;
11
+}
12
13
+void print_foo()
14
15
+ while(foo == 0)
16
+ {
17
+ std::this_thread::yield();
18
+ }
19
+ std::cout << "foo: " << foo << std::endl;
20
21
22
23
+int main()
24
25
+ std::thread first(print_foo);
26
+ std::thread second(set_foo, 10);
27
+ first.join();
28
+ second.join();
29
+ return 0;
30
31
0 commit comments