回答編集履歴
2
修正
answer
CHANGED
|
@@ -4,13 +4,17 @@
|
|
|
4
4
|
#include <future>
|
|
5
5
|
#include <mutex>
|
|
6
6
|
#include <chrono>
|
|
7
|
+
#include <atomic>
|
|
7
8
|
|
|
8
9
|
int main(void) {
|
|
9
10
|
using namespace std;
|
|
10
11
|
using namespace std::chrono;
|
|
11
12
|
|
|
12
13
|
mutex mtx;
|
|
14
|
+
/* 修正: int→atomic<int>
|
|
15
|
+
read時にmutexで排他してないので。
|
|
16
|
+
int値のreadは実質atomicに行われるだろうから"まず"大丈夫なんだろけど念のため */
|
|
13
|
-
int shop_apple = 100;
|
|
17
|
+
atomic<int> shop_apple = 100;
|
|
14
18
|
|
|
15
19
|
future<int> A = async([&]() -> int {
|
|
16
20
|
int apple = 0;
|
1
微修正
answer
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
リアルタイムにリンゴの買い出しさせてみた。
|
|
1
2
|
```C++
|
|
2
3
|
#include <iostream>
|
|
3
4
|
#include <future>
|