-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path5_access_demotion.cpp
48 lines (39 loc) · 1.35 KB
/
5_access_demotion.cpp
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
/* 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>
namespace rg = redGrapes;
int main(int, char*[])
{
spdlog::set_level(spdlog::level::trace);
auto rg = rg::init();
auto a = rg.createIOResource<int>();
rg.emplace_task(
[&](auto a)
{
std::cout << "f1 writes A" << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(1));
std::cout << "f1 now only reads A" << std::endl;
rg.update_properties(decltype(rg)::RGTask::TaskProperties::Patch::Builder()
.remove_resources({a.write()})
.add_resources({a.read()}));
std::this_thread::sleep_for(std::chrono::seconds(1));
std::cout << "f1 done" << std::endl;
},
a.write());
rg.emplace_task(
[]([[maybe_unused]] auto a)
{
std::cout << "f2 reads A" << std::endl;
std::cout << "f2 done" << std::endl;
},
a.read());
return 0;
}