-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgt_deadlock_detect_test.cpp
60 lines (43 loc) · 1.39 KB
/
gt_deadlock_detect_test.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
49
50
51
52
53
54
55
56
57
58
59
60
#include "graphtoy.hpp"
#include <array>
using namespace graphtoy;
struct DerpKernel: GtKernelBase {
explicit DerpKernel(GtContext *ctx): GtKernelBase(ctx) {}
GtKernelIoStream<int> *m_input = addIoStream<int>();
GtKernelIoStream<size_t> *m_input2 = addIoStream<size_t>();
private:
GtKernelCoro kernelMain() override {
co_return; // :D
}
};
template<typename T>
struct SourceKernel: GtKernelBase {
explicit SourceKernel(GtContext *ctx): GtKernelBase(ctx) {}
GtKernelIoStream<T> *m_output = addIoStream<T>();
private:
GtKernelCoro kernelMain() override {
T val = 0;
while (true) {
co_await m_output->write(++val);
}
}
};
static constexpr size_t g_numSources = 3;
int main() {
GtContext ctx{};
std::array<SourceKernel<int> *, g_numSources> sources;
for (auto& src: sources) {
src = &ctx.addKernel<SourceKernel<int>>();
}
auto& merger = ctx.addKernel<GtPacketStreamMerger<int>>(g_numSources);
auto& anotherSource = ctx.addKernel<SourceKernel<size_t>>();
auto& derp = ctx.addKernel<DerpKernel>();
for (size_t i = 0; i < sources.size(); ++i) {
ctx.connect(sources[i]->m_output, merger.input(i));
}
ctx.connect(merger.output(), derp.m_input);
ctx.connect(anotherSource.m_output, derp.m_input2);
// This will warn about a deadlock
ctx.runToCompletion();
return 0;
}