Skip to content

Commit 6b49346

Browse files
authored
refactor: replace atomic counter with plain int in RunInLoopTest2 (#368)
- Change std::atomic<int> counter to int counter since all operations are guaranteed to execute in the same event loop thread
1 parent 26ef5df commit 6b49346

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

trantor/tests/RunInLoopTest2.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
int main()
1010
{
11-
std::atomic<uint64_t> counter;
12-
counter = 0;
11+
// Local variable to be used within the loopThread
12+
uint64_t counter = 0;
1313
std::promise<int> pro;
1414
auto ft = pro.get_future();
1515
trantor::EventLoopThread loopThread;
@@ -20,7 +20,7 @@ int main()
2020
{
2121
loop->queueInLoop([&counter, &pro]() {
2222
++counter;
23-
if (counter.load() == 110000)
23+
if (counter == 110000)
2424
pro.set_value(1);
2525
});
2626
}
@@ -32,13 +32,13 @@ int main()
3232
{
3333
loop->runInLoop([&counter, &pro]() {
3434
++counter;
35-
if (counter.load() == 110000)
35+
if (counter == 110000)
3636
pro.set_value(1);
3737
});
3838
}
3939
}).detach();
4040
}
4141
loopThread.run();
4242
ft.get();
43-
std::cout << "counter=" << counter.load() << std::endl;
43+
std::cout << "counter=" << counter << std::endl;
4444
}

0 commit comments

Comments
 (0)