fix async deadlock

This commit is contained in:
tqcq
2024-03-28 22:19:28 +08:00
parent fd46ca62ae
commit 181823d4fe
6 changed files with 126 additions and 88 deletions

View File

@@ -5,15 +5,6 @@
// clang-format off
#include <async++.h>
// clang-format on
namespace async {
sled::FiberScheduler &
default_scheduler()
{
static sled::FiberScheduler scheduler;
return scheduler;
}
}// namespace async
namespace sled {
@@ -25,13 +16,33 @@ SleepWaitHandler(async::task_wait_handle t)
event.Wait(sled::Event::kForever);
}
FiberScheduler::FiberScheduler()
{
}
void
FiberScheduler::schedule(async::task_run_handle t)
{
static ThreadPool thread_pool;
auto move_on_copy = sled::MakeMoveOnCopy(t);
// thread_pool.PostTask([move_on_copy] { move_on_copy.value.run_with_wait_handler(SleepWaitHandler); });
thread_pool.submit([move_on_copy] { move_on_copy.value.run_with_wait_handler(SleepWaitHandler); });
// thread_pool.submit([move_on_copy] { move_on_copy.value.run(); });
}
}// namespace sled
// clang-format on
namespace async {
sled::FiberScheduler &
default_scheduler()
{
static sled::FiberScheduler scheduler;
return scheduler;
}
void
detail::wait_for_task(task_base *wait_task)
{
sled::SleepWaitHandler(task_wait_handle(wait_task));
}
}// namespace async

View File

@@ -28,3 +28,12 @@ TEST(Async, parallel_for)
// wg.Wait();
for (int i = 0; i < count; i++) { EXPECT_TRUE(values[i]) << i; }
}
TEST(Async, parallel_reduce)
{
auto r = async::parallel_reduce(async::irange(1, 5), 0, [](int x, int y) {
LOGD("", "{},{}", x, y);
return x + y;
});
LOGD("", "{}", r);
}