Skip to content

Commit f61f520

Browse files
karzhenkovandreasbuhr
authored andcommitted
Try a workaround to prevent nested continuations
1 parent f3bf926 commit f61f520

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

test/async_auto_reset_event_tests.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ TEST_CASE("multi-threaded")
9191
{
9292
cppcoro::static_thread_pool tp{ 3 };
9393

94-
unsigned max_depth = 0;
95-
9694
auto run = [&]() -> cppcoro::task<>
9795
{
9896
cppcoro::async_auto_reset_event event;
@@ -105,12 +103,18 @@ TEST_CASE("multi-threaded")
105103
co_await event;
106104
++value;
107105

108-
thread_local unsigned depth = 0;
109-
if (depth > max_depth) max_depth = depth;
106+
thread_local volatile bool nested = false;
107+
108+
if (nested)
109+
{
110+
co_await tp.schedule();
111+
assert(!nested);
112+
}
113+
114+
nested = true;
115+
cppcoro::scoped_lambda cleanup = [] { nested = false; };
110116

111-
depth += 1;
112117
event.set();
113-
depth -= 1;
114118
};
115119

116120
auto startSignaller = [&]() -> cppcoro::task<>
@@ -143,8 +147,6 @@ TEST_CASE("multi-threaded")
143147
}
144148

145149
cppcoro::sync_wait(cppcoro::when_all(std::move(tasks)));
146-
147-
CHECK_MESSAGE(max_depth == 0, "Nested continuations detected");
148150
}
149151

150152
TEST_SUITE_END();

0 commit comments

Comments
 (0)