From 4c04e417eb233a3d8263e6a17eadf122ade835b5 Mon Sep 17 00:00:00 2001 From: khalilluo Date: Tue, 25 Feb 2025 16:52:34 +0800 Subject: [PATCH] refactor: replace atomic counter with plain int in RunInLoopTest2 - Change std::atomic counter to int counter since all operations are guaranteed to execute in the same event loop thread --- trantor/tests/RunInLoopTest2.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/trantor/tests/RunInLoopTest2.cc b/trantor/tests/RunInLoopTest2.cc index ce969a37..0b68e845 100644 --- a/trantor/tests/RunInLoopTest2.cc +++ b/trantor/tests/RunInLoopTest2.cc @@ -8,8 +8,8 @@ int main() { - std::atomic counter; - counter = 0; + // Local variable to be used within the loopThread + uint64_t counter = 0; std::promise pro; auto ft = pro.get_future(); trantor::EventLoopThread loopThread; @@ -20,7 +20,7 @@ int main() { loop->queueInLoop([&counter, &pro]() { ++counter; - if (counter.load() == 110000) + if (counter == 110000) pro.set_value(1); }); } @@ -32,7 +32,7 @@ int main() { loop->runInLoop([&counter, &pro]() { ++counter; - if (counter.load() == 110000) + if (counter == 110000) pro.set_value(1); }); } @@ -40,5 +40,5 @@ int main() } loopThread.run(); ft.get(); - std::cout << "counter=" << counter.load() << std::endl; + std::cout << "counter=" << counter << std::endl; }