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 2ca7395 commit a5004f2Copy full SHA for a5004f2
cpp_11/003_std_atomic_long_long.cpp
@@ -1 +1,30 @@
1
-1
+#include <iostream>
2
+#include <thread>
3
+#include <atomic>
4
+#include <array>
5
+
6
+std::atomic<long long> data{10};
7
+std::array<long long, 5> return_values{};
8
9
+void do_work(int thread_num)
10
+{
11
+ long long val = data.fetch_add(1, std::memory_order_relaxed);
12
+ return_values[thread_num] = val;
13
+}
14
15
+int main()
16
17
+ {
18
+ std::jthread th0{do_work, 0};
19
+ std::jthread th1{do_work, 1};
20
+ std::jthread th2{do_work, 2};
21
+ std::jthread th3{do_work, 3};
22
+ std::jthread th4{do_work, 4};
23
+ }
24
25
+ std::cout << "Result : " << data << '\n';
26
27
+ for (long long val : return_values) {
28
+ std::cout << "Seen return value : " << val << std::endl;
29
30
0 commit comments