Skip to content

Commit ef32334

Browse files
committed
ThreadBack: reduce hdlFinishedTasks
1 parent 4e621e1 commit ef32334

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

ut/thread/ThPoolBackTest.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ TEST_F(ThPoolBackTest, invalid_maxThread)
1414
[] { return true; }, // entryFn
1515
[](bool) {} // backFn
1616
)) << "REQ: can create new task";
17-
while (threadBack_.hdlFinishedTasks() == 0); // REQ: wait new task done
17+
while (threadBack_.hdlFinishedTasks() == 0)
18+
timedwait(); // REQ: wait new task done
1819
}
1920

2021
// ***********************************************************************************************
@@ -33,7 +34,8 @@ TEST_F(ThPoolBackTest, performance)
3334
},
3435
[](bool) {} // backFn
3536
));
36-
for (size_t nHandled = 0; nHandled < maxThread; nHandled += thPoolBack.hdlFinishedTasks());
37+
for (size_t nHandled = 0; nHandled < maxThread; nHandled += thPoolBack.hdlFinishedTasks())
38+
timedwait();
3739
auto dur = duration_cast<chrono::microseconds>(high_resolution_clock::now() - start);
3840
HID("ThPoolBack cost=" << dur.count() << "us");
3941
// - belinb03 : ~ 20 faster than AsyncBack
@@ -50,7 +52,8 @@ TEST_F(ThPoolBackTest, performance)
5052
},
5153
[](bool) {} // backFn
5254
));
53-
for (size_t nHandled = 0; nHandled < maxThread; nHandled += asyncBack.hdlFinishedTasks());
55+
for (size_t nHandled = 0; nHandled < maxThread; nHandled += asyncBack.hdlFinishedTasks())
56+
timedwait();
5457
dur = duration_cast<chrono::microseconds>(high_resolution_clock::now() - start);
5558
HID("AsyncBack cost=" << dur.count() << "us");
5659
}

ut/thread/ThreadBackTest.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,14 @@ TEST_F(THREAD_BACK_TEST, canHandle_someThreadDone_whileOtherRunning)
135135
while (threadBack_.hdlFinishedTasks() == 0)
136136
{
137137
INF("both threads not end yet, wait...");
138-
this_thread::yield();
138+
timedwait();
139139
}
140140

141141
canEnd = true; // 1st thread keep running while 2nd is done
142142
while (threadBack_.hdlFinishedTasks() == 0) // no timedwait() so keep occupy cpu
143143
{
144144
INF("2nd thread done, wait 1st done...")
145-
this_thread::yield();
145+
timedwait();
146146
}
147147
}
148148

@@ -159,7 +159,8 @@ TEST_F(THREAD_BACK_TEST, GOLD_entryFn_notify_insteadof_timeout)
159159
auto dur = duration_cast<std::chrono::milliseconds>(high_resolution_clock::now() - start);
160160
EXPECT_LT(dur.count(), 500) << "REQ: entryFn end shall notify g_semToMainTH instead of timeout";
161161

162-
while (threadBack_.hdlFinishedTasks() == 0); // clear all threads
162+
while (threadBack_.hdlFinishedTasks() == 0) // clear all threads
163+
timedwait();
163164
}
164165

165166
#define ABNORMAL

0 commit comments

Comments
 (0)