Repository navigation
Expand file tree
/
Copy path3_functors_with_resources.cpp
More file actions
64 lines (55 loc) · 1.73 KB
/
Copy path3_functors_with_resources.cpp
File metadata and controls
64 lines (55 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* Copyright 2019-2024 Michael Sippel, Tapish Narwal
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <redGrapes/redGrapes.hpp>
#include <redGrapes/resource/ioresource.hpp>
#include <chrono>
#include <iostream>
#include <thread>
int main(void)
{
spdlog::set_level(spdlog::level::trace);
auto rg = redGrapes::init();
auto a = rg.createIOResource<int>();
auto b = rg.createIOResource<int>();
for(int i = 0; i < 1; ++i)
{
rg.emplace_task(
[](auto a)
{
std::cout << "Write to A" << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(1));
*a = 4;
std::cout << "Write A done" << std::endl;
},
a.write());
rg.emplace_task(
[](auto a)
{
std::cout << "Read A: " << *a << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(1));
},
a.read());
rg.emplace_task(
[](auto b)
{
std::cout << "Write to B" << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(3));
*b = 7;
std::cout << "Write B done" << std::endl;
},
b.write());
rg.emplace_task(
[](auto a, auto b)
{
std::cout << "Read A & B: " << *a << ", " << *b << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(1));
},
a.read(),
b.read());
}
return 0;
}