Bypass clang thread_local error. (#2016)

This commit is contained in:
Nitromelon 2024-04-29 11:32:30 +08:00 committed by GitHub
parent e79d5170b4
commit 439ddd8dbe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 5 deletions

View File

@ -198,16 +198,16 @@ DROGON_TEST(AsyncWaitLifetime)
DROGON_TEST(SwitchThread) DROGON_TEST(SwitchThread)
{ {
thread_local int num{0};
trantor::EventLoopThread thread; trantor::EventLoopThread thread;
thread.getLoop()->setIndex(12345);
thread.run(); thread.run();
thread.getLoop()->queueInLoop([]() { num = 100; });
auto switch_thread = [TEST_CTX, &thread]() -> Task<> { auto switch_thread = [TEST_CTX, &thread]() -> Task<> {
CHECK(num == 0);
co_await switchThreadCoro(thread.getLoop()); co_await switchThreadCoro(thread.getLoop());
CHECK(num == 100); auto currentLoop = trantor::EventLoop::getEventLoopOfCurrentThread();
thread.getLoop()->quit(); MANDATE(currentLoop != nullptr);
CHECK(currentLoop->index() == 12345);
currentLoop->quit();
}; };
sync_wait(switch_thread()); sync_wait(switch_thread());
thread.wait(); thread.wait();